Re: [Bug report] srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write on module load
From: Paul E. McKenney
Date: Mon Nov 16 2026 - 13:11:20 EST
On Sat, Nov 14, 2026 at 09:30:00AM +0800, Guikun Yang wrote:
> From: Guikun Yang <yangguikun19@xxxxxx>
> To: "Paul E. McKenney" <paulmck@xxxxxxxxxx>
> Cc: Luis Chamberlain <mcgrof@xxxxxxxxxx>, Petr Pavlu <petr.pavlu@xxxxxxxx>,
> rcu@xxxxxxxxxxxxxxx, linux-modules@xxxxxxxxxxxxxxx,
> linux-kernel@xxxxxxxxxxxxxxx
> Subject: [Bug report] srcu_module_coming() dereferences unvalidated
> ___srcu_struct_ptrs entries - wild kernel-memory write on module load
>
> Hi Paul, Luis,
>
> The module loader hands the contents of the ___srcu_struct_ptrs section
> to SRCU as an array of absolute struct srcu_struct * pointers, with no
> validation of any entry. srcu_module_coming() then writes through each
> one during the MODULE_STATE_COMING notification, inside init_module().
> A crafted module whose synthetic section contains an arbitrary 64-bit
> value therefore gets a kernel-heap pointer written to an
> attacker-chosen address.
>
> Oops: general protection fault, probably for non-canonical address
> 0xe00006aaa0000021: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN NOPTI
> KASAN: probably user-memory-access in range
> [0x0000555500000108-0x000055550000010f]
> RIP: 0010:srcu_module_notify+0x480/0x610
> RAX: 0000607f57d191c0 (alloc_percpu return, the value being written)
> RBX: 0000555500000100 (the section entry, verbatim from the file)
> RDI: 0000555500000108 (&ssp->sda)
> notifier_call_chain
> blocking_notifier_call_chain_robust
> load_module
> __do_sys_init_module
>
> ## The three pieces
>
> Loader, zero validation (kernel/module/main.c):
>
> mod->srcu_struct_ptrs = section_objs(info, "___srcu_struct_ptrs",
> sizeof(*mod->srcu_struct_ptrs),
> &mod->num_srcu_structs);
>
> section_objs() counts entries and returns sh_addr; the bytes' validity
> is entirely up to the ELF file.
>
> Generator, absolute pointer (include/linux/srcutree.h):
>
> struct srcu_struct * const __srcu_struct_##name
> __section("___srcu_struct_ptrs") = &name
>
> Unlike __tracepoints_ptrs (PREL32 self-relative on x86), this is a
> link-time absolute address. In a hand-built section the bytes are
> whatever the attacker writes, and since no .rela entry targets them,
> apply_relocations() never touches them either.
>
> Consumer, write on load (kernel/rcu/srcutree.c, unchanged from 7.3 to
> mainline 2026-11-14):
>
> ssp = *(sspp++);
> ssp->sda = alloc_percpu(struct srcu_data); /* wild write */
> if (WARN_ON_ONCE(!ssp->sda))
> return -ENOMEM;
> ssp->srcu_ctrp = &ssp->sda->srcu_ctrs[0]; /* second write */
>
> ssp->sda sits at offset 8, so an entry value V makes the kernel write
> a freshly allocated percpu pointer to V+8, and a pointer derived from
> it to V. The unload/rollback path (srcu_module_going()) dereferences
> ssp->srcu_sup and frees ssp->sda through the same unchecked entries.
>
> ## Why this is more than a crash
>
> The write value is a kernel heap address and the target is a fully
> attacker-chosen 64-bit address. Pointing the entry at a
> userland-readable mapping leaks the percpu allocation address directly
> to userspace, defeating percpu-base randomization and contributing to
> KASLR defeat. Pointing it at any zero-filled kernel address lands the
> write. A non-canonical target gives the deterministic #GP above
> (reproduced 7.3.0, KASAN inline, DEBUG_PAGEALLOC).
>
> ## The fix has an in-tree precedent
>
> jump_label.c validates exactly this class of pointer in the same
> module-notification path (kernel/jump_label.c:716):
>
> if (within_module((unsigned long)key, mod)) {
> static_key_set_entries(key, iter);
> continue;
> }
>
> The suggested fix mirrors it in srcu_module_coming() and
> srcu_module_going():
>
> for (i = 0; i < mod->num_srcu_structs; i++) {
> ssp = *(sspp++);
> + if (!ssp || !within_module((unsigned long)ssp, mod))
> + return -EINVAL;
> ssp->sda = alloc_percpu(struct srcu_data);
Good catch, thank you!
I presume that srcu_module_going() would instead do something like this?
> + if (!ssp || !within_module((unsigned long)ssp, mod))
> + continue;
Either way, would you be willing to send a proper patch?
Thanx, Paul
> __tracepoints_ptrs and __bpf_raw_tp_map are sibling pointer sections
> with the same exposure; a shared check in find_module_sections()
> would cover the class, but the SRCU entries are the concrete
> write-what-where primitive demonstrated here.
>
> This is the second report in this series: the relocation r_offset
> bounds gap went out as <mod-r-offset-oob-20261113@xxxxxx> yesterday.
> Both are cases of the module loader consuming section contents that
> its ELF validity layer never checked.
>
> ## Reproducer
>
> Carrier is a real xt_mark.ko built from the same tree as the test
> kernel (vermagic, this_module size, 11 undefined symbols all
> matching). A section synthesizer appends an 8-byte
> ___srcu_struct_ptrs entry (0x0000555500000100), fixing shstrtab,
> e_shnum and e_shoff. Same boot, three steps:
>
> 1. load original xt_mark.ko -> 0
> 2. unload -> 0
> 3. load synthesized module -> the Oops above
>
> The A/B pair, the synthesizer and the reproducer are available on
> request.
>
> Tested on 7.3.0; kernel/rcu/srcutree.c and the loader path are
> unchanged in mainline as of 2026-11-14.
>
> Thanks,
> Guikun Yang
>
>