Skip to contentSkip to conversation

btrfs: prevent to set invalid default subvolid

PATCH In review Satoru Takeuchi 3 participants 3 messages Sep 12, 2017 – Sep 13, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: prevent to set invalid default subvolid

btrfs sub set-default succeeds to set an ID which isn't corresponding to any fs/file tree. If such the bad ID is set to a filesystem, we can't mount this filesystem without specifying subvol or subvolid mount options.

---
 fs/btrfs/ioctl.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/ioctl.c +4 -0
index ae8fbf9..8e1bc19 100644
@@ -4057,6 +4057,10 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
 		ret = PTR_ERR(new_root);
 		goto out;
 	}
+	if (!is_fstree(new_root->objectid)) {
+		ret = -ENOENT;
+		goto out;
+	}
 
 	path = btrfs_alloc_path();
 	if (!path) {
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Satoru Takeuchi

btrfs sub set-default succeeds to set an ID which isn't corresponding to any fs/file tree. If such the bad ID is set to a filesystem, we can't mount this filesystem without specifying subvol or subvolid mount options.

I was a little worried about the handling of special treeid like RECLOC and DATA_RELOC, but is_fstree() called btrfs_qgroup_level() check so we don't need to worry about that.

Nice catch.

Thanks,
Qu

Quoted 20 lines
(quoted diff) +0 -1
-
  fs/btrfs/ioctl.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/btrfs/ioctl.c +4 -0
index ae8fbf9..8e1bc19 100644
@@ -4057,6 +4057,10 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
  		ret = PTR_ERR(new_root);
  		goto out;
  	}
+	if (!is_fstree(new_root->objectid)) {
+		ret = -ENOENT;
+		goto out;
+	}
 
  	path = btrfs_alloc_path();
  	if (!path) {