Re: [PATCH 4/9] srcu: Validate callback arguments
From: Paul E. McKenney
Date: Fri Oct 23 2026 - 15:40:14 EST
On Fri, Oct 23, 2026 at 06:18:36PM +0800, Kunwu Chan wrote:
> Check callback-head alignment and reject NULL callback
> functions in the SRCU callback registration paths.
>
> Signed-off-by: Kunwu Chan <chentao@xxxxxxxxxx>
For 4/9-6/9:
Reviewed-by: Paul E. McKenney <paulmck@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..1993ddbdb828 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -1529,6 +1529,13 @@ static void srcu_do_enqueue(struct srcu_struct *ssp, struct rcu_head *rhp,
> static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
> rcu_callback_t func, bool do_norm)
> {
> + /* 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;
> +
> if (WARN_ON_ONCE(ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC))
> return; // Leak the callback rather than corrupt SRCU state.
>
> --
> 2.43.0
>