Re: [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range
From: Bradley Morgan
Date: Tue Nov 17 2026 - 11:25:03 EST
On 17 November 2026 02:00:00 GMT, Guikun Yang <yangguikun19@xxxxxx> 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().
>
>---
>
>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.
For the next series of patches, could you please send it as new threads?
lore makes me sad because of the mess.
>
>Signed-off-by: Guikun Yang <yangguikun19@xxxxxx>
look, makes enough sense
Reviewed-by: Bradley Morgan <bradley.morgan@xxxxxxxxx>
>---
> 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);
>
>
--- Thanks!