poll: rust: allow poll_table ptrs to be null
Alice Ryhl
maintainerPATCH v2 1/1 poll: rust: allow poll_table ptrs to be null
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.)
---
This issue was discovered from a syzkaller report on Rust Binder.
Intended for Christian Brauner's tree.
---
Changes in v2:
- Reword safety comment on poll_wait. (Benno)
- Link to v1: https://lore.kernel.org/r/[email protected]
--- rust/helpers/helpers.c | 1 + rust/helpers/poll.c | 10 +++++++ rust/kernel/sync/poll.rs | 68 ++++++++++++++++++------------------------------ 3 files changed, 37 insertions(+), 42 deletions(-)
rust/helpers/helpers.c +1 -0
@@ -30,6 +30,7 @@#include "platform.c" #include "pci.c" #include "pid_namespace.c" +#include "poll.c" #include "rbtree.c" #include "rcu.c" #include "refcount.c"
rust/helpers/poll.c new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/export.h> +#include <linux/poll.h> + +void rust_helper_poll_wait (struct file *filp,wait_queue_head_t *wait_address, +poll_table *p) +{ +poll_wait (filp, wait_address, p); +}
rust/kernel/sync/poll.rs +26 -42
93 lines not on this page · raw message
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250620-poll-table-null-bf9a6a6c569e
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>