Re: [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range

From: Paul E. McKenney

Date: Wed Nov 18 2026 - 00:09:22 EST


On Tue, Nov 17, 2026 at 10:00:00AM +0800, Guikun Yang wrote:
> As discussed, here is the formal patch. Exactly as you presumed:
> srcu_module_going() needs the same check, because a module whose
> coming() fails the validation still gets a MODULE_STATE_GOING
> notification via the robust call in prepare_coming_module().
>
> ---

I have pulled this in for review and testing, thank you! And with
Bradley's Reviewed-by, however, Joel is doing the upcoming merge window,
so its eventual disposition is up to him.

The next time you send a patch, please skip the first paragraph and
the "---". These cause the automation to keep the above paragraph
and to throw away the real commit log below.

Which I compensated for, so no harm done. This time. ;-)

Thanx, Paul

> The entries of the ___srcu_struct_ptrs section are absolute pointers
> emitted by DEFINE_SRCU() in module .data. load_info() hands the raw
> section to RCU (kernel/module/main.c), and srcu_module_coming()
> dereferences each entry and writes through it:
>
> ssp = *(sspp++);
> ssp->sda = alloc_percpu(struct srcu_data);
> ssp->srcu_ctrp = &ssp->sda->srcu_ctrs[0];
>
> A malicious or corrupted module image can point an entry anywhere in
> the kernel address space; nothing on the load path validates it, so
> this is an arbitrary-address write primitive (an 8-byte percpu
> pointer at offset 8 of the target).
>
> The static-key loader already handles the same shape of section with
> a range check (kernel/jump_label.c):
>
> if (within_module((unsigned long)key, mod))
>
> Apply the same check to both module-notification paths. coming()
> rejects the module load outright; going() skips the entry, because
> going() runs even for modules that never passed coming(), and those
> entries never got per-CPU data allocated.
>
> Signed-off-by: Guikun Yang <yangguikun19@xxxxxx>
> ---
> kernel/rcu/srcutree.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index 2b0e2b2d2..412265757 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -2498,6 +2498,8 @@ static int srcu_module_coming(struct module *mod)
>
> for (i = 0; i < mod->num_srcu_structs; i++) {
> ssp = *(sspp++);
> + if (WARN_ON_ONCE(!within_module((unsigned long)ssp, mod)))
> + return -EINVAL;
> ssp->sda = alloc_percpu(struct srcu_data);
> if (WARN_ON_ONCE(!ssp->sda))
> return -ENOMEM;
> @@ -2521,6 +2523,8 @@ static void srcu_module_going(struct module *mod)
> srcu_defer_flush();
> for (i = 0; i < mod->num_srcu_structs; i++) {
> ssp = *(sspp++);
> + if (WARN_ON_ONCE(!within_module((unsigned long)ssp, mod)))
> + continue;
> if (!rcu_seq_state(smp_load_acquire(&ssp->srcu_sup->srcu_gp_seq_needed)) &&
> !WARN_ON_ONCE(!ssp->srcu_sup->sda_is_static))
> cleanup_srcu_struct(ssp);
>
> --
> 2.34.1
>