Re: [PATCH v2 0/2] implement OA2_INHERIT_CRED flag for openat2()

From: Andy Lutomirski
Date: Wed Apr 24 2024 - 23:32:15 EST


On Wed, Apr 24, 2024 at 6:44 PM Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
>
> On Wed, Apr 24, 2024 at 05:43:02PM -0700, Andy Lutomirski wrote:
>
> > I like that, but you're blocking it the wrong way. My concern is that
> > someone does dfd = open("/proc/PID/fd/3") and then openat(dfd, ...,
> > OA2_INHERIT_CRED); IIRC open("/proc/PID/fd/3") is extremely magical
> > and returns the _same open file description_ (struct file) as PID's fd
> > 3.
>
> No, it doesn't. We could implement that, but if we do that'll be
> *not* a part of procfs and it's going to be limited to current task
> only.

Egads -- why would we want to implement that? In the apparently
incorrect model in my head, Linux's behavior was ridiculous and only
made sense for some historical reason. But I wonder why I thought
that.

Diving a tiny bit down the rabbit hole, I have a copy of TLPI on my
bookshelf, and I bought it quite a long time ago and read a bunch of
it when I got it, and my copy is *wrong*! Section 5.11 has the
behavior of /dev/fd very clearly documented as working like dup().

And here it is: erratum 107. Whoopsies!

https://man7.org/tlpi/errata/index.html

Anyway, I retract that particular objection to the series. But I
wouldn't be shocked if one can break a normal modern systemd using the
patchset -- systemd does all kinds of fun things involving passing
file descriptors around.

--Andy