From: Christian Engelmayer Date: Tue, 20 Oct 2015 22:50:06 +0000 (+0200) Subject: btrfs: fix possible leak in btrfs_ioctl_balance() X-Git-Tag: v4.1.12-92~201^2~70 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=787135d01f9b455726d28963fc08669dda5d032f;p=users%2Fjedix%2Flinux-maple.git btrfs: fix possible leak in btrfs_ioctl_balance() Orabug: 22623825 commit 0f89abf56abbd0e1c6e3cef9813e6d9f05383c1e upstream. Commit 8eb934591f8b ("btrfs: check unsupported filters in balance arguments") adds a jump to exit label out_bargs in case the argument check fails. At this point in addition to the bargs memory, the memory for struct btrfs_balance_control has already been allocated. Ownership of bctl is passed to btrfs_balance() in the good case, thus the memory is not freed due to the introduced jump. Make sure that the memory gets freed in any case as necessary. Detected by Coverity CID 1328378. Signed-off-by: Christian Engelmayer Reviewed-by: David Sterba Signed-off-by: Chris Mason Signed-off-by: Greg Kroah-Hartman (cherry picked from commit ee03d02ebc5dd0ee414fc47eb3992e8d3aa7396e) Signed-off-by: Dan Duval --- diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index af3dd3c55ef1..8b2c82ce36b3 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4494,7 +4494,7 @@ locked: if (bctl->flags & ~(BTRFS_BALANCE_ARGS_MASK | BTRFS_BALANCE_TYPE_MASK)) { ret = -EINVAL; - goto out_bargs; + goto out_bctl; } do_balance: @@ -4508,12 +4508,15 @@ do_balance: need_unlock = false; ret = btrfs_balance(bctl, bargs); + bctl = NULL; if (arg) { if (copy_to_user(arg, bargs, sizeof(*bargs))) ret = -EFAULT; } +out_bctl: + kfree(bctl); out_bargs: kfree(bargs); out_unlock: