Btrfs: do not overwrite error return value in the device replace ioctl
PATCH 1/1 Btrfs: do not overwrite error return value in the device replace ioctl
From: Filipe Manana <[email protected]>
If the call to btrfs_dev_replace_by_ioctl() 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 no error happened before.
--- fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ioctl.c +1 -1
@@ -4401,7 +4401,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_fs_info *fs_info,break ; } -if (copy_to_user (arg, p,sizeof (*p))) +if (ret ==0 &©_to_user (arg, p,sizeof (*p))) ret = -EFAULT ; out:kfree (p);
Signature · 1 line
2.11.0
Quoted 17 lines · On 12/15/2018 03:45 AM, [email protected] wrote:
From: Filipe Manana <[email protected]>
If the call to
btrfs_dev_replace_by_ioctl()failed we would overwrite the error returned to user space with-EFAULTif the call tocopy_to_user()failed as well. Fix that by callingcopy_to_user()only if no error happened before.Signed-off-by Filipe Manana <[email protected]>--- fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/ioctl.c +0
-0
fs/btrfs/ioctl.c static long btrfs_ioctl_dev_replace(struct btrfs_fs_info *fs_info, · line 4404
Quoted 5 lines
fs/btrfs/ioctl.c +1
-1@@ -4401,7 +4401,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_fs_info *fs_info,break ; } -if (copy_to_user (arg, p,sizeof (*p))) +if (ret ==0 &©_to_user (arg, p,sizeof (*p)))
Its the same thing here too.. we copy ret to args->result even if it fails. Now with this patch, if ret is non-zero, its not in args->result at the userland anymore. If there is any tool which just checks args->result will be at problem, which I think is rare, should be ok. It would have been nice to have this design as in this patch, in the original code.
------
530 ret = btrfs_dev_replace_start(fs_info,args->start.tgtdev_name,
531 args->start.srcdevid,
532 args->start.srcdev_name,
533args->start.cont_reading_from_srcdev_mode);
534 args->result = ret;
--------
Quoted 4 lines
fs/btrfs/ioctl.c +0
-0ret = -EFAULT ; out:kfree (p);
PATCH v2 1/1 Btrfs: do not overwrite error return value in the device replace ioctl
In reply to [email protected]From: Filipe Manana <[email protected]>
If the call to btrfs_dev_replace_by_ioctl() 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 no error happened before or a device replace operation was canceled.
---
V2: Considered the case where the device replace operation is canceled.
fs/btrfs/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/ioctl.c +1 -1
@@ -4462,7 +4462,7 @@ static long btrfs_ioctl_dev_replace(struct btrfs_fs_info *fs_info,break ; } -if (copy_to_user (arg, p,sizeof (*p))) +if ((ret ==0 || ret == -ECANCELED ) &©_to_user (arg, p,sizeof (*p))) ret = -EFAULT ; out:kfree (p);
Signature · 1 line
2.11.0
Quoted 8 lines · On Tue, Jan 08, 2019 at 11:42:09AM +0000, [email protected] wrote:
From: Filipe Manana <[email protected]>
If the call to
btrfs_dev_replace_by_ioctl()failed we would overwrite the error returned to user space with-EFAULTif the call tocopy_to_user()failed as well. Fix that by callingcopy_to_user()only if no error happened before or a device replace operation was canceled.Signed-off-by Filipe Manana <[email protected]>