Skip to content

Commit 5a11724

Browse files
osandovmaharmstone
authored andcommitted
libbtrfsutil: don't check for UID 0 in subvolume_info()
btrfs_util_subvolume_info() explicitly checks whether geteuid() == 0 to decide whether to use the unprivileged BTRFS_IOC_GET_SUBVOL_INFO ioctl or the privileged BTRFS_IOC_TREE_SEARCH ioctl. This breaks in user namespaces: $ unshare -r python3 -c 'import btrfsutil; print(btrfsutil.subvolume_info("/"))' Traceback (most recent call last): File "<string>", line 1, in <module> btrfsutil.BtrfsUtilError: [BtrfsUtilError 12 Errno 1] Could not search B-tree: Operation not permitted: '/' The unprivileged ioctl has been supported since Linux 4.18. Let's try the unprivileged ioctl first, then fall back to the privileged version only if it isn't supported. Signed-off-by: Omar Sandoval <osandov@fb.com>
1 parent c75b2f2 commit 5a11724

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libbtrfsutil/subvolume.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,10 @@ PUBLIC enum btrfs_util_error btrfs_util_subvolume_info_fd(int fd, uint64_t id,
451451
if (err)
452452
return err;
453453

454-
if (!is_root())
455-
return get_subvolume_info_unprivileged(fd, subvol);
454+
err = get_subvolume_info_unprivileged(fd, subvol);
455+
if (err != BTRFS_UTIL_ERROR_GET_SUBVOL_INFO_FAILED ||
456+
errno != ENOTTY)
457+
return err;
456458

457459
err = btrfs_util_subvolume_id_fd(fd, &id);
458460
if (err)

0 commit comments

Comments
 (0)