Re: [PATCH 1/3] btrfs: return -EINVAL if some user wants to remove uuid/data_reloc tree
From: Anand Jain <hidden>
Date: 2021-06-28 10:59:25
On 28/6/21 6:16 pm, Qu Wenruo wrote:
Ioctl BTRFS_IOC_SNAP_DESTROY_V2 supports a flag to delete a subvolume using root id directly. We check the target root id against BTRFS_FIRST_FREE_OBJECTID, but not again BTRFS_LAST_FREE_OBJECTID. This means if user passes rootid like DATA_RELOC (-9) or TREE_RELOC (-8), we can pass the check, then get caught by later dentry check and got error number -ENOENT, other than -EINVAL. It's not a big deal as we have extra safe nets to prevent those trees get removed, it's still better to do the extra check and return proper -EINVAL error. Signed-off-by: Qu Wenruo <redacted>
Reviewed-by: Anand Jain <redacted> Thanks, -Anand
quoted hunk ↗ jump to hunk
--- fs/btrfs/ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 0ba98e08a029..889e27c24e3a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c@@ -2932,7 +2932,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, if (err) goto out; } else { - if (vol_args2->subvolid < BTRFS_FIRST_FREE_OBJECTID) { + if (vol_args2->subvolid < BTRFS_FIRST_FREE_OBJECTID || + vol_args2->subvolid > BTRFS_LAST_FREE_OBJECTID) { err = -EINVAL; goto out; }