From: Filipe Manana Date: Fri, 14 Dec 2018 19:50:17 +0000 (+0000) Subject: Btrfs: do not overwrite scrub error with fault error in scrub ioctl X-Git-Tag: v5.1-rc1~47^2~95 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=06fe39ab15a6a4;p=linux-block.git Btrfs: do not overwrite scrub error with fault error in scrub ioctl If scrub returned an error and then the copy_to_user() call did not succeed, we would overwrite the error returned by scrub with -EFAULT. Fix that by calling copy_to_user() only if btrfs_scrub_dev() returned success. 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 9c8e1734429c..d34e54d80149 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4381,7 +4381,7 @@ static long btrfs_ioctl_scrub(struct file *file, void __user *arg) &sa->progress, sa->flags & BTRFS_SCRUB_READONLY, 0); - if (copy_to_user(arg, sa, sizeof(*sa))) + if (ret == 0 && copy_to_user(arg, sa, sizeof(*sa))) ret = -EFAULT; if (!(sa->flags & BTRFS_SCRUB_READONLY))