From: Omar Sandoval <osandov@osandov.com>
To: linux-btrfs@vger.kernel.org
Cc: kernel-team@fb.com
Subject: [PATCH 2/8] libbtrfsutil: don't check for UID 0 in subvolume_info()
Date: Fri, 21 Jun 2024 11:53:31 -0700 [thread overview]
Message-ID: <0455327c82f908ef22491b40957d4f4bbd30bc60.1718995160.git.osandov@fb.com> (raw)
In-Reply-To: <cover.1718995160.git.osandov@fb.com>
From: Omar Sandoval <osandov@fb.com>
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>
---
libbtrfsutil/subvolume.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libbtrfsutil/subvolume.c b/libbtrfsutil/subvolume.c
index 1f0f2d2b..70f2ec70 100644
--- a/libbtrfsutil/subvolume.c
+++ b/libbtrfsutil/subvolume.c
@@ -451,8 +451,10 @@ PUBLIC enum btrfs_util_error btrfs_util_subvolume_info_fd(int fd, uint64_t id,
if (err)
return err;
- if (!is_root())
- return get_subvolume_info_unprivileged(fd, subvol);
+ err = get_subvolume_info_unprivileged(fd, subvol);
+ if (err != BTRFS_UTIL_ERROR_GET_SUBVOL_INFO_FAILED ||
+ errno != ENOTTY)
+ return err;
err = btrfs_util_subvolume_id_fd(fd, &id);
if (err)
--
2.45.2
next prev parent reply other threads:[~2024-06-21 18:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-21 18:53 [PATCH 0/8] btrfs-progs: add subvol list options for sane path behavior Omar Sandoval
2024-06-21 18:53 ` [PATCH 1/8] libbtrfsutil: fix accidentally closing fd passed to subvolume iterator Omar Sandoval
2024-06-21 18:53 ` Omar Sandoval [this message]
2024-06-21 18:53 ` [PATCH 3/8] libbtrfsutil: don't check for UID 0 in " Omar Sandoval
2024-06-21 18:53 ` [PATCH 4/8] btrfs-progs: subvol list: remove unused raw layout code Omar Sandoval
2024-06-21 18:53 ` [PATCH 5/8] btrfs-progs: subvol list: remove unused filters Omar Sandoval
2024-06-21 18:53 ` [PATCH 6/8] btrfs-progs: subvol list: document and test actual behavior of paths Omar Sandoval
2024-06-21 18:53 ` [PATCH 7/8] btrfs-progs: subvol list: use libbtrfsutil Omar Sandoval
2024-06-21 18:53 ` [PATCH 8/8] btrfs-progs: subvol list: add sane -O and -A options Omar Sandoval
2024-06-25 15:34 ` [PATCH 0/8] btrfs-progs: add subvol list options for sane path behavior David Sterba
2024-07-01 21:52 ` Omar Sandoval
2024-07-03 23:40 ` David Sterba
2024-07-11 23:59 ` Omar Sandoval
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0455327c82f908ef22491b40957d4f4bbd30bc60.1718995160.git.osandov@fb.com \
--to=osandov@osandov.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox