[PATCH for-v7.5 05/11] srcu: Validate callback arguments

From: Joel Fernandes

Date: Thu Nov 12 2026 - 21:50:58 EST


From: Kunwu Chan <kunwu.chan@xxxxxxxxx>

Check callback-head alignment and reject NULL callback
functions in the SRCU callback registration paths.

Reviewed-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
Signed-off-by: Kunwu Chan <chentao@xxxxxxxxxx>
Reviewed-by: Joel Fernandes <jfern@xxxxxxxxxx>
Signed-off-by: Joel Fernandes <jfern@xxxxxxxxxx>
---
kernel/rcu/srcutiny.c | 7 +++++++
kernel/rcu/srcutree.c | 7 +++++++
2 files changed, 14 insertions(+)

diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index 3ee28885b96f..98864977bed2 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -291,6 +291,13 @@ EXPORT_SYMBOL_GPL(srcu_defer_drain);
void call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
rcu_callback_t func)
{
+ /* Misaligned rcu_head! */
+ WARN_ON_ONCE((unsigned long)rhp & (sizeof(void *) - 1));
+
+ /* Avoid NULL dereference if callback is NULL. */
+ if (WARN_ON_ONCE(!func))
+ return;
+
/* Record the caller: the irq_work's stack says nothing about it. */
kasan_record_aux_stack(rhp);

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 46fe2f0cef85..76f074f67299 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1532,6 +1532,13 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
if (WARN_ON_ONCE(ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC))
return; // Leak the callback rather than corrupt SRCU state.

+ /* Misaligned rcu_head! */
+ WARN_ON_ONCE((unsigned long)rhp & (sizeof(void *) - 1));
+
+ /* Avoid NULL dereference if callback is NULL. */
+ if (WARN_ON_ONCE(!func))
+ return;
+
/* Record the caller: the irq_work's stack says nothing about it. */
kasan_record_aux_stack(rhp);

--
2.54.0