Commit 1b8acfa
libbtrfsutil: don't check for UID 0 in subvolume iterator
The subvolume iterator API explicitly checks whether geteuid() == 0 to
decide whether to use the unprivileged BTRFS_IOC_GET_SUBVOL_ROOTREF and
BTRFS_IOC_INO_LOOKUP_USER ioctls or the privileged BTRFS_IOC_TREE_SEARCH
ioctl. This breaks in user namespaces:
$ unshare -r python3 -c 'import btrfsutil; print(list(btrfsutil.SubvolumeIterator("/home")))'
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
Instead of the explicit check, let's try the privileged mode first, and
if it fails with a permission error, fall back to the unprivileged mode
(which has been supported since Linux 4.18). Note that we have to try
the privileged mode first, since even for privileged users, the
unprivileged mode may omit some subvolumes that are hidden by filesystem
mounts.
Signed-off-by: Omar Sandoval <osandov@fb.com>1 parent 5a11724 commit 1b8acfa
1 file changed
+28
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 35 | | |
41 | 36 | | |
42 | 37 | | |
| |||
807 | 802 | | |
808 | 803 | | |
809 | 804 | | |
810 | | - | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
811 | 810 | | |
812 | 811 | | |
813 | 812 | | |
| |||
1009 | 1008 | | |
1010 | 1009 | | |
1011 | 1010 | | |
1012 | | - | |
| 1011 | + | |
1013 | 1012 | | |
1014 | 1013 | | |
1015 | 1014 | | |
1016 | 1015 | | |
1017 | 1016 | | |
1018 | 1017 | | |
1019 | | - | |
| 1018 | + | |
1020 | 1019 | | |
1021 | 1020 | | |
1022 | 1021 | | |
| |||
1666 | 1665 | | |
1667 | 1666 | | |
1668 | 1667 | | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
1669 | 1673 | | |
1670 | | - | |
1671 | | - | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
1675 | 1689 | | |
| 1690 | + | |
1676 | 1691 | | |
1677 | 1692 | | |
1678 | 1693 | | |
| |||
0 commit comments