From: Josh Triplett <josh@joshtriplett.org>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
io-uring@vger.kernel.org, linux-arch@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Arnd Bergmann <arnd@arndb.de>, Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH v3 1/3] fs: Support setting a minimum fd for "lowest available fd" allocation
Date: Wed, 8 Apr 2020 20:17:08 -0700 [thread overview]
Message-ID: <20200409031708.GC6149@localhost> (raw)
In-Reply-To: <20200408120040.mtkqmymfazrv3lqk@yavin.dot.cyphar.com>
On Wed, Apr 08, 2020 at 10:00:40PM +1000, Aleksa Sarai wrote:
> On 2020-04-07, Josh Triplett <josh@joshtriplett.org> wrote:
> > Some applications want to prevent the usual "lowest available fd"
> > allocation from allocating certain file descriptors. For instance, they
> > may want to prevent allocation of a closed fd 0, 1, or 2 other than via
> > dup2/dup3, or reserve some low file descriptors for other purposes.
> >
> > Add a prctl to increase the minimum fd and return the previous minimum.
> >
> > System calls that allocate a specific file descriptor, such as
> > dup2/dup3, ignore this minimum.
> >
> > exec resets the minimum fd, to prevent one program from interfering with
> > another program's expectations about fd allocation.
>
> Why is it implemented as an "increase the value" interface? It feels
> like this is meant to avoid some kind of security trap (with a library
> reducing the value) but it means that if you want to temporarily raise
> the minimum fd number it's not possible (without re-exec()ing yourself,
> which is hardly a fun thing to do).
>
> Then again, this might've been discussed before and I missed it...
It was: the previous version was a "get" and "set" interface. That
interface didn't allow for the possibility that something else in the
process had already set a minimum. This new atomic increase interface
(which also serves as a "get" interface if you pass 0) makes it possible
for a userspace library to reserve a range. (You have no guarantee about
previously allocated descriptors in that range, but you know that no
*new* automatically allocated descriptors will appear in that range,
which suffices; userspace can do the rest.)
- Josh Triplett
next prev parent reply other threads:[~2020-04-09 3:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-08 6:56 [PATCH v3 0/3] Support userspace-selected fds Josh Triplett
2020-04-08 6:57 ` [PATCH v3 1/3] fs: Support setting a minimum fd for "lowest available fd" allocation Josh Triplett
2020-04-08 12:00 ` Aleksa Sarai
2020-04-09 3:17 ` Josh Triplett [this message]
2020-04-08 6:57 ` [PATCH v3 2/3] fs: openat2: Extend open_how to allow userspace-selected fds Josh Triplett
2020-04-08 12:23 ` Aleksa Sarai
2020-04-09 5:00 ` Josh Triplett
2020-04-09 8:10 ` Aleksa Sarai
2020-04-08 6:57 ` [PATCH v3 3/3] fs: pipe2: Support O_SPECIFIC_FD Josh Triplett
2020-04-08 12:26 ` [PATCH v3 0/3] Support userspace-selected fds Aleksa Sarai
2020-04-09 3:19 ` Josh Triplett
-- strict thread matches above, loose matches on Subject: below --
2020-04-04 5:57 Josh Triplett
2020-04-04 5:58 ` [PATCH v3 1/3] fs: Support setting a minimum fd for "lowest available fd" allocation Josh Triplett
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=20200409031708.GC6149@localhost \
--to=josh@joshtriplett.org \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=cyphar@cyphar.com \
--cc=io-uring@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.