btrfs: fix possible leak in btrfs_ioctl_balance()
authorChristian Engelmayer <cengelma@gmx.at>
Tue, 20 Oct 2015 22:50:06 +0000 (00:50 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 9 Nov 2015 22:33:39 +0000 (14:33 -0800)
commitee03d02ebc5dd0ee414fc47eb3992e8d3aa7396e
tree96e99aa9d8fdf194a7002b6fd810ca97124c9cd0
parentd35e462164987724e4a1d20a55351e52181464aa
btrfs: fix possible leak in btrfs_ioctl_balance()

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 <cengelma@gmx.at>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/ioctl.c