From: Filipe Manana Date: Tue, 8 Jan 2019 11:42:01 +0000 (+0000) Subject: Btrfs: do not overwrite error return value in the balance ioctl X-Git-Tag: v5.1-rc1~138^2~72 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d00c2d9c76975d70089418dc1447b51da3a6a118;p=users%2Fjedix%2Flinux-maple.git Btrfs: do not overwrite error return value in the balance ioctl If the call to btrfs_balance() failed we would overwrite the error returned to user space with -EFAULT if the call to copy_to_user() failed as well. Fix that by calling copy_to_user() only if btrfs_balance() returned success or was canceled. Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index b07b19acdbb1..c21cc408556d 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4781,7 +4781,7 @@ do_balance: ret = btrfs_balance(fs_info, bctl, bargs); bctl = NULL; - if (arg) { + if ((ret == 0 || ret == -ECANCELED) && arg) { if (copy_to_user(arg, bargs, sizeof(*bargs))) ret = -EFAULT; }