Skip to contentSkip to conversation

btrfs: array overflow in btrfs_ioctl_rm_dev_v2()

PATCH In review Dan Carpenter 3 participants 3 messages Feb 18, 2016

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

PATCH 1/1 btrfs: array overflow in btrfs_ioctl_rm_dev_v2()

We were putting the NUL terminator at BTRFS_PATH_NAME_MAX (4087) bytes instead of BTRFS_SUBVOL_NAME_MAX (4039) so it corrupted memory.

Fixes 22af1a869288 ('btrfs: introduce device delete by devid')
fs/btrfs/ioctl.c +1 -1
index 5224fc8..77c61b4 100644
@@ -2700,7 +2700,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
 	if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID) {
 		ret = btrfs_rm_device(root, NULL, vol_args->devid);
 	} else {
-		vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
+		vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0';
 		ret = btrfs_rm_device(root, vol_args->name, 0);
 	}
 	mutex_unlock(&root->fs_info->volume_mutex);
#1 lore raw

Thanks Dan.
Chris pointed out as well. We are working on it..
Just one concern when device is added the max device length is BTRFS_PATH_NAME_MAX. However below fix is proper from the vol_args perspective.

Thanks, Anand

Quoted 24 lines · Dan Carpenter

We were putting the NUL terminator at BTRFS_PATH_NAME_MAX (4087) bytes instead of BTRFS_SUBVOL_NAME_MAX (4039) so it corrupted memory.

Fixes 22af1a869288 ('btrfs: introduce device delete by devid')
fs/btrfs/ioctl.c +1 -2
index 5224fc8..77c61b4 100644
@@ -2700,7 +2700,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
  	if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID) {
  		ret = btrfs_rm_device(root, NULL, vol_args->devid);
  	} else {
-		vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
+		vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0';
  		ret = btrfs_rm_device(root, vol_args->name, 0);
  	}
  	mutex_unlock(&root->fs_info->volume_mutex);
--

To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 4 lines · Anand Jain

Thanks Dan.
Chris pointed out as well. We are working on it..

In for next since yesterday.

Quoted 3 lines

Just one concern when device is added the max device length is BTRFS_PATH_NAME_MAX. However below fix is proper from the vol_args perspective.

Yeah, there's mess in the various PATH constants, but they're all > 4000 and that should be enough for most uses.