From: Christian Brauner <firstname.lastname@example.org>
To: Amir Goldstein <email@example.com>
Cc: "Christian Göttsche" <firstname.lastname@example.org>,
email@example.com, "Miklos Szeredi" <firstname.lastname@example.org>,
"Linux API" <email@example.com>,
"Alexander Viro" <firstname.lastname@example.org>,
Subject: Re: [RFC PATCH] f*xattr: allow O_PATH descriptors
Date: Wed, 8 Jun 2022 14:48:08 +0200 [thread overview]
Message-ID: <20220608124808.uylo5lntzfgxxmns@wittgenstein> (raw)
On Wed, Jun 08, 2022 at 03:28:52PM +0300, Amir Goldstein wrote:
> On Wed, Jun 8, 2022 at 2:57 PM Christian Brauner <email@example.com> wrote:
> > On Tue, Jun 07, 2022 at 05:31:39PM +0200, Christian Göttsche wrote:
> > > From: Miklos Szeredi <firstname.lastname@example.org>
> > >
> > > Support file descriptors obtained via O_PATH for extended attribute
> > > operations.
> > >
> > > Extended attributes are for example used by SELinux for the security
> > > context of file objects. To avoid time-of-check-time-of-use issues while
> > > setting those contexts it is advisable to pin the file in question and
> > > operate on a file descriptor instead of the path name. This can be
> > > emulated in userspace via /proc/self/fd/NN  but requires a procfs,
> > > which might not be mounted e.g. inside of chroots, see.
> > >
> > > : https://github.com/SELinuxProject/selinux/commit/7e979b56fd2cee28f647376a7233d2ac2d12ca50
> > > : https://github.com/SELinuxProject/selinux/commit/de285252a1801397306032e070793889c9466845
> > >
> > > Original patch by Miklos Szeredi <email@example.com>
> > > https://firstname.lastname@example.org/
> > >
> > > > While this carries a minute risk of someone relying on the property of
> > > > xattr syscalls rejecting O_PATH descriptors, it saves the trouble of
> > > > introducing another set of syscalls.
> > > >
> > > > Only file->f_path and file->f_inode are accessed in these functions.
> > > >
> > > > Current versions return EBADF, hence easy to detect the presense of
> > > > this feature and fall back in case it's missing.
> > >
> > > CC: email@example.com
> > > CC: firstname.lastname@example.org
> > > Signed-off-by: Christian Göttsche <email@example.com>
> > > ---
> > I'd be somewhat fine with getxattr and listxattr but I'm worried that
> > setxattr/removexattr waters down O_PATH semantics even more. I don't
> > want O_PATH fds to be useable for operations which are semantically
> > equivalent to a write.
> It is not really semantically equivalent to a write if it works on a
> O_RDONLY fd already.
The fact that it works on a O_RDONLY fd has always been weird. And is
probably a bug. If you look at xattr_permission() you can see that it
checks for MAY_WRITE for set operations... setxattr() writes to disk for
real filesystems. I don't know how much closer to a write this can get.
In general, one semantic aberration doesn't justify piling another one
(And one thing that speaks for O_RDONLY is at least that it actually
opens the file wheres O_PATH doesn't.)
> > In sensitive environments such as service management/container runtimes
> > we often send O_PATH fds around precisely because it is restricted what
> > they can be used for. I'd prefer to not to plug at this string.
> But unless I am mistaken, path_setxattr() and syscall_fsetxattr()
> are almost identical w.r.t permission checks and everything else.
> So this change introduces nothing new that a user in said environment
> cannot already accomplish with setxattr().
> Besides, as the commit message said, doing setxattr() on an O_PATH
> fd is already possible with setxattr("/proc/self/$fd"), so whatever security
> hole you are trying to prevent is already wide open.
That is very much a something that we're trying to restrict for this
exact reason and is one of the main motivator for upgrade mask in
openat2(). If I want to send a O_PATH around I want it to not be
upgradable. Aleksa is working on upgrade masks with openat2() (see 
and part of the original patchset in . O_PATH semantics don't need to
next prev parent reply other threads:[~2022-06-08 12:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 15:31 [RFC PATCH] f*xattr: allow O_PATH descriptors Christian Göttsche
2022-06-08 5:13 ` Amir Goldstein
2022-06-08 11:27 ` Christian Brauner
2022-06-08 12:28 ` Amir Goldstein
2022-06-08 12:48 ` Christian Brauner [this message]
2022-06-08 15:12 ` Amir Goldstein
2022-06-09 8:56 ` Christian Brauner
2022-06-18 3:18 ` Aleksa Sarai
2022-06-18 9:11 ` Amir Goldstein
2022-06-18 11:19 ` Christian Göttsche
2022-06-18 15:30 ` Amir Goldstein
2022-06-20 6:07 ` Aleksa Sarai
2022-06-20 7:45 ` Amir Goldstein
2022-06-22 2:57 ` Aleksa Sarai
2022-08-19 18:05 ` Christian Göttsche
2022-08-19 20:27 ` Amir Goldstein
2022-06-08 16:53 ` Andreas Dilger
2022-06-09 4:35 ` Amir Goldstein
2022-06-09 9:14 ` Christian Göttsche
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:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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;
as well as URLs for NNTP newsgroup(s).