From: "Benno Lossin" <lossin@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jan Kara" <jack@suse.cz>, "Miguel Ojeda" <ojeda@kernel.org>,
"Christian Brauner" <brauner@kernel.org>
Cc: "Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] poll: rust: allow poll_table ptrs to be null
Date: Sun, 22 Jun 2025 09:55:22 +0200 [thread overview]
Message-ID: <DASWFQXR9V54.18EU85NWBUC97@kernel.org> (raw)
In-Reply-To: <20250620-poll-table-null-v1-1-b3fe92a4fd0d@google.com>
On Fri Jun 20, 2025 at 1:49 PM CEST, Alice Ryhl wrote:
> It's possible for a poll_table to be null. This can happen if an
> end-user just wants to know if a resource has events right now without
> registering a waiter for when events become available. Furthermore,
> these null pointers should be handled transparently by the API, so we
> should not change `from_ptr` to return an `Option`. Thus, change
> `PollTable` to wrap a raw pointer rather than use a reference so that
> you can pass null.
>
> Comments mentioning `struct poll_table` are changed to just `poll_table`
> since `poll_table` is a typedef. (It's a typedef because it's supposed
> to be opaque.)
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> This issue was discovered from a syzkaller report on Rust Binder.
>
> Intended for Christian Brauner's tree.
> ---
> rust/helpers/helpers.c | 1 +
> rust/helpers/poll.c | 10 ++++++++
> rust/kernel/sync/poll.rs | 65 +++++++++++++++++-------------------------------
> 3 files changed, 34 insertions(+), 42 deletions(-)
Looks good, one safety comment concern below, with that fixed:
Reviewed-by: Benno Lossin <lossin@kernel.org>
> /// Register this [`PollTable`] with the provided [`PollCondVar`], so that it can be notified
> /// using the condition variable.
> - pub fn register_wait(&mut self, file: &File, cv: &PollCondVar) {
> - if let Some(qproc) = self.get_qproc() {
> - // SAFETY: The pointers to `file` and `self` need to be valid for the duration of this
> - // call to `qproc`, which they are because they are references.
> - //
> - // The `cv.wait_queue_head` pointer must be valid until an rcu grace period after the
> - // waiter is removed. The `PollCondVar` is pinned, so before `cv.wait_queue_head` can
> - // be destroyed, the destructor must run. That destructor first removes all waiters,
> - // and then waits for an rcu grace period. Therefore, `cv.wait_queue_head` is valid for
> - // long enough.
> - unsafe { qproc(file.as_ptr() as _, cv.wait_queue_head.get(), self.0.get()) };
> - }
> + pub fn register_wait(&self, file: &File, cv: &PollCondVar) {
> + // SAFETY: The pointers `self.table` and `file` are valid for the duration of this call.
`self.table` might be null, which I think we agreed to is not "valid".
> + // The `cv.wait_queue_head` pointer must be valid until an rcu grace period after the
> + // waiter is removed. The `PollCondVar` is pinned, so before `cv.wait_queue_head` can be
> + // destroyed, the destructor must run. That destructor first removes all waiters, and then
> + // waits for an rcu grace period. Therefore, `cv.wait_queue_head` is valid for long enough.
Could you use bullet points for the different requirements?
---
Cheers,
Benno
> + unsafe { bindings::poll_wait(file.as_ptr(), cv.wait_queue_head.get(), self.table) }
> }
> }
>
>
> ---
> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
> change-id: 20250620-poll-table-null-bf9a6a6c569e
>
> Best regards,
next prev parent reply other threads:[~2025-06-22 7:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 11:49 [PATCH] poll: rust: allow poll_table ptrs to be null Alice Ryhl
2025-06-20 12:31 ` Benno Lossin
2025-06-20 13:19 ` Alice Ryhl
2025-06-22 7:50 ` Benno Lossin
2025-06-22 7:55 ` Benno Lossin [this message]
2025-06-23 11:56 ` Christian Brauner
2025-06-23 13:57 ` Benno Lossin
2025-06-23 13:58 ` Alice Ryhl
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=DASWFQXR9V54.18EU85NWBUC97@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--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 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).