Skip to contentSkip to conversation

btrfs: fix error pointer dereference in btrfs_ioctl_rm_dev_v2()

PATCH In review Dan Carpenter 3 participants 3 messages Nov 16, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix error pointer dereference in btrfs_ioctl_rm_dev_v2()

If memdup_user() fails the error handing will crash when it tries to kfree() an error pointer. Just return directly because there is no cleanup required.

Fixes 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")
---
 fs/btrfs/ioctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/ioctl.c +2 -4
index fb8cc9642ac4..32df384b40c8 100644
@@ -3187,10 +3187,8 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
 		return -EPERM;
 
 	vol_args = memdup_user(arg, sizeof(*vol_args));
-	if (IS_ERR(vol_args)) {
-		ret = PTR_ERR(vol_args);
-		goto out;
-	}
+	if (IS_ERR(vol_args))
+		return PTR_ERR(vol_args);
 
 	if (vol_args->flags & ~BTRFS_DEVICE_REMOVE_ARGS_MASK) {
 		ret = -EOPNOTSUPP;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

If memdup_user() fails the error handing will crash when it tries to kfree() an error pointer. Just return directly because there is no cleanup required.

Fixes 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")

Thanks,

Josef

#2 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter

If memdup_user() fails the error handing will crash when it tries to kfree() an error pointer. Just return directly because there is no cleanup required.

Fixes 1a15eb724aae ("btrfs: use btrfs_get_dev_args_from_path in dev removal ioctls")

Added to misc-next, thanks.