From: Christian Brauner <brauner@kernel.org>
To: Gary Guo <gary@garyguo.net>
Cc: "Georgios Androutsopoulos" <georgeandrout13@gmail.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Miguel Ojeda" <ojeda@kernel.org>, "Jan Kara" <jack@suse.cz>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
linux-fsdevel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: file: handle fd table teardown in file descriptor APIs
Date: Fri, 25 Sep 2026 17:15:10 +0200 [thread overview]
Message-ID: <20260925-entfernen-kocht-anbot-a03d3ea7e01a@brauner> (raw)
In-Reply-To: <DLKFTVSN56P2.2NHCFW6NIUOAH@garyguo.net>
On Sun, Sep 20, 2026 at 09:48:54PM +0100, Gary Guo wrote:
> On Sun Sep 20, 2026 at 9:01 PM BST, Georgios Androutsopoulos wrote:
> > Several Rust file descriptor APIs rely on `current->files` being
> > available. However, `exit_files()` clears it while execution may still
> > continue on the same task.
> >
> > This affects `LocalFile::fget()` and the
> > `FileDescriptorReservation` operations that call
> > `get_unused_fd_flags()`, `fd_install()`, and `put_unused_fd()`.
> > `FileDescriptorReservation` cannot cross task boundaries, but remaining
> > on the same task does not guarantee that `current->files` is still
> > available when these operations are performed.
> >
> > Guard the affected operations against a missing `current->files`.
> > `LocalFile::fget()` returns `EBADF` and
> > `FileDescriptorReservation::get_unused_fd_flags()` returns `EMFILE`.
> > For the infallible `fd_install()` and drop paths, warn once and avoid
> > calling the corresponding C helper when the fd table is already gone.
> >
> > This prevents NULL dereferences through these safe Rust APIs after
> > `exit_files()`.
>
> I suppose we could add these checks to C side instead, although perhaps one may
> say "its bad caller code and not worth checking"?
It is a bug to call fd_install() or anything like that post
exit_files(). Whatever code is doing that needs to get fixed.
Similarly it is a bug to call fd_install() on kernel thread which do not
have files at all. So whoever you're doing this for is breaching core
api assumptions big time and I would like a detailed explanation
otherwise I see no reason to merge this.
prev parent reply other threads:[~2026-09-25 15:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 20:01 Georgios Androutsopoulos
2026-09-20 20:48 ` Gary Guo
2026-09-22 18:30 ` Georgios Androutsopoulos
2026-09-22 19:55 ` Gary Guo
2026-10-16 16:26 ` Miguel Ojeda
2026-09-25 15:15 ` Christian Brauner [this message]
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=20260925-entfernen-kocht-anbot-a03d3ea7e01a@brauner \
--to=brauner@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=georgeandrout13@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=work@onurozkan.dev \
/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
all inboxes | Powered by JetHome®