* [Bug report] srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write on module load
[not found] <mod-r-offset-oob-20261113@qq.com>
@ 2026-11-14 2:00 ` Guikun Yang
[not found] ` <srcu-struct-ptrs-wildwrite-20261114@qq.com>
[not found] ` <tencent_0836A27053A7BED946E49CE04D27A31E7D09@qq.com>
2 siblings, 0 replies; 6+ messages in thread
From: Guikun Yang @ 2026-11-14 2:00 UTC (permalink / raw)
To: Paul E. McKenney
Cc: Luis Chamberlain, Petr Pavlu, linux-rcu, linux-modules, linux-kernel
From: Guikun Yang <yangguikun19@qq.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>, Petr Pavlu <petr.pavlu@suse.com>,
linux-rcu@vger.kernel.org, linux-modules@vger.kernel.org,
linux-kernel@vger.kernel.org
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);
__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@qq.com> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bug report] x86-64 apply_returns() decodes attacker-controlled addresses from unvalidated .return_sites entries - wild read on module load
2026-11-14 8:00 ` [Bug report] x86-64 apply_returns() decodes attacker-controlled addresses from unvalidated .return_sites entries - wild read " Guikun Yang
@ 2026-11-14 6:20 ` Borislav Petkov
0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2026-11-14 6:20 UTC (permalink / raw)
To: Guikun Yang
Cc: Peter Zijlstra (Intel),
Ingo Molnar, Arnaldo Carvalho de Melo, Luis Chamberlain,
Petr Pavlu, Thomas Gleixner, Dave Hansen, x86, linux-modules,
linux-kernel
On Sat, Nov 14, 2026 at 04:00:00PM +0800, Guikun Yang wrote:
> From: Guikun Yang <yangguikun19@qq.com>
> To: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
> Ingo Molnar <mingo@redhat.com>,
> Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Luis Chamberlain <mcgrof@kernel.org>, Petr Pavlu <petr.pavlu@suse.com>,
> Thomas Gleixner <tglx@linutronix.de>, Borislav Petkov <bp@alien8.de>,
> Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
> linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
> Subject: [Bug report] x86-64 apply_returns() decodes attacker-controlled
> addresses from unvalidated .return_sites entries - wild read on module load
>
> Hi Peter, Ingo,
>
> The .return_sites section of a module is consumed by apply_returns()
> without any validation of the computed addresses. Each entry is an s32
> relative offset whose final value is fully attacker-controlled via the
> R_X86_64_PC32 relocation addend (that relocation path has no overflow
If you can load modules on a system, you've already won.
Why would you even do some silly exploit like that?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug report] x86-64 apply_returns() decodes attacker-controlled addresses from unvalidated .return_sites entries - wild read on module load
[not found] ` <srcu-struct-ptrs-wildwrite-20261114@qq.com>
@ 2026-11-14 8:00 ` Guikun Yang
2026-11-14 6:20 ` Borislav Petkov
0 siblings, 1 reply; 6+ messages in thread
From: Guikun Yang @ 2026-11-14 8:00 UTC (permalink / raw)
To: Peter Zijlstra (Intel), Ingo Molnar, Arnaldo Carvalho de Melo
Cc: Luis Chamberlain, Petr Pavlu, Thomas Gleixner, Borislav Petkov,
Dave Hansen, x86, linux-modules, linux-kernel
From: Guikun Yang <yangguikun19@qq.com>
To: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>, Petr Pavlu <petr.pavlu@suse.com>,
Thomas Gleixner <tglx@linutronix.de>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [Bug report] x86-64 apply_returns() decodes attacker-controlled
addresses from unvalidated .return_sites entries - wild read on module load
Hi Peter, Ingo,
The .return_sites section of a module is consumed by apply_returns()
without any validation of the computed addresses. Each entry is an s32
relative offset whose final value is fully attacker-controlled via the
R_X86_64_PC32 relocation addend (that relocation path has no overflow
check either), and the decoder dereferences the resulting address
byte-by-byte inside init_module() - a wild kernel read, deterministic,
KASLR-independent.
BUG: unable to handle page fault for address: ffffffff402000e7
Oops: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN NOPTI
RIP: 0010:insn_get_prefixes.part.0+0xc1/0x14c0
RBX: ffffffff402000e7 (the forged site pointer)
Call Trace:
insn_decode
apply_returns
module_finalize
load_module
__do_sys_init_module
The faulting address is the module's .return_sites location plus the
forged s32 - pointing into the unmapped hole below the kernel image.
## The path
module_finalize() hands the section over verbatim
(arch/x86/kernel/module.c):
if (returns) {
void *rseg = (void *)returns->sh_addr;
apply_returns(rseg, rseg + returns->sh_size);
}
apply_returns() computes and decodes without any bounds check
(arch/x86/kernel/alternative.c):
for (s = start; s < end; s++) {
void *dest = NULL, *addr = (void *)s + *s;
struct insn insn;
...
ret = insn_decode_kernel(&insn, addr); /* wild read */
insn_decode_kernel() expands to insn_decode(..., MAX_INSN_SIZE,
INSN_MODE_KERN); the buffer length only bounds the decoder's own
15-byte window, not the validity of the address. insn_get_prefixes()
fetches bytes with get_unaligned() one at a time from that address.
## How the s32 becomes attacker-controlled
objtool emits .return_sites as zero bytes plus R_X86_64_PC32
relocations against .text symbols. __write_relocate_add() handles that
type as:
case R_X86_64_PC32:
case R_X86_64_PLT32:
val -= (u64)loc;
size = 4;
break;
with no overflow check (R_X86_64_32/32S have one; PC32/PLT32 do not).
Modifying one r_addend in .rela.return_sites therefore controls the
s32 that ends up in the section - the write target bytes are already
zero, so nothing else in the file needs to change.
## Impact: not only a crash
The decode-failure and thunk-mismatch paths both print kernel memory
from the wild address:
WARN_ONCE(dest != &__x86_return_thunk,
"missing return thunk: %pS-%pS: %*ph",
addr, dest, 5, addr);
That %*ph dumps five bytes read from the attacker-chosen address into
the kernel log. A local user who can read dmesg gets a five-byte
peek at any address within +/-2GB of the module's .return_sites
per load attempt - a repeatable kernel-memory disclosure, in addition
to the deterministic page fault.
## apply_retpolines() is the same pattern
The sibling consumer (arch/x86/kernel/alternative.c) is identical in
shape:
for (s = start; s < end; s++) {
void *addr = (void *)s + *s;
...
ret = insn_decode_kernel(&insn, addr);
and is reachable the same way through .retpoline_sites. Both should
be fixed together.
## The fix has an in-tree precedent in the same call sequence
callthunks_patch_module_calls() processes .call_sites in the same
module_finalize() path and already validates exactly this class of
address (arch/x86/kernel/callthunks.c):
static __init_or_module void patch_call(void *addr, const struct core_text *ct)
{
...
if (!within_coretext(ct, addr))
return;
with ct built from mod->mem[MOD_TEXT]. The suggested fix mirrors it
for .return_sites and .retpoline_sites - reject any computed site
address outside the module's text before decoding:
struct core_text ct = {
.base = (unsigned long)mod->mem[MOD_TEXT].base,
.end = (unsigned long)mod->mem[MOD_TEXT].base + mod->mem[MOD_TEXT].size,
};
for (s = start; s < end; s++) {
void *addr = (void *)s + *s;
+ if (!within_coretext(&ct, addr))
+ continue;
This is the third report in this series of unvalidated module
section contents (relocation r_offset <mod-r-offset-oob-20261113@qq.com>,
SRCU pointer section <srcu-struct-ptrs-wildwrite-20261114@qq.com>);
callthunks shows the loader already knows how to bound this class of
address - apply_returns/apply_retpolines are the paths it was never
applied to.
## Reproducer
Carrier is a real xt_mark.ko built from the same tree as the test
kernel. A single entry of .rela.return_sites has its r_addend changed
by 0x80000000; nothing else in the file differs. Same boot:
1. load original xt_mark.ko -> init_module returns 0
2. unload -> 0
3. load the modified module -> the Oops above
The synthesizer (with sanity checks on sh_link/sh_info/entsize/
relocation type/target-zero), the A/B pair and the serial log are
available on request.
Tested on 7.3.0; arch/x86/kernel/alternative.c and module.c are
unchanged in mainline as of 2026-11-14 (both fetched and compared
byte-for-byte).
Thanks,
Guikun Yang
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bug report] srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write on module load
[not found] ` <tencent_0836A27053A7BED946E49CE04D27A31E7D09@qq.com>
@ 2026-11-16 18:11 ` Paul E. McKenney
2026-11-17 2:00 ` [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range Guikun Yang
1 sibling, 0 replies; 6+ messages in thread
From: Paul E. McKenney @ 2026-11-16 18:11 UTC (permalink / raw)
To: Guikun Yang
Cc: Luis Chamberlain, Petr Pavlu, rcu, linux-modules, linux-kernel
On Sat, Nov 14, 2026 at 09:30:00AM +0800, Guikun Yang wrote:
> From: Guikun Yang <yangguikun19@qq.com>
> To: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Luis Chamberlain <mcgrof@kernel.org>, Petr Pavlu <petr.pavlu@suse.com>,
> rcu@vger.kernel.org, linux-modules@vger.kernel.org,
> linux-kernel@vger.kernel.org
> 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@qq.com> 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
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range
[not found] ` <tencent_0836A27053A7BED946E49CE04D27A31E7D09@qq.com>
2026-11-16 18:11 ` [Bug report] srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write " Paul E. McKenney
@ 2026-11-17 2:00 ` Guikun Yang
2026-11-17 16:24 ` Bradley Morgan
1 sibling, 1 reply; 6+ messages in thread
From: Guikun Yang @ 2026-11-17 2:00 UTC (permalink / raw)
To: Paul E. McKenney; +Cc: rcu, linux-kernel
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.
Signed-off-by: Guikun Yang <yangguikun19@qq.com>
---
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range
2026-11-17 2:00 ` [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range Guikun Yang
@ 2026-11-17 16:24 ` Bradley Morgan
0 siblings, 0 replies; 6+ messages in thread
From: Bradley Morgan @ 2026-11-17 16:24 UTC (permalink / raw)
To: yangguikun19; +Cc: linux-kernel, paulmck, rcu
On 17 November 2026 02:00:00 GMT, Guikun Yang <yangguikun19@qq.com> 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@qq.com>
look, makes enough sense
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>---
> 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!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 16:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <mod-r-offset-oob-20261113@qq.com>
2026-11-14 2:00 ` [Bug report] srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write on module load Guikun Yang
[not found] ` <srcu-struct-ptrs-wildwrite-20261114@qq.com>
2026-11-14 8:00 ` [Bug report] x86-64 apply_returns() decodes attacker-controlled addresses from unvalidated .return_sites entries - wild read " Guikun Yang
2026-11-14 6:20 ` Borislav Petkov
[not found] ` <tencent_0836A27053A7BED946E49CE04D27A31E7D09@qq.com>
2026-11-16 18:11 ` [Bug report] srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write " Paul E. McKenney
2026-11-17 2:00 ` [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range Guikun Yang
2026-11-17 16:24 ` Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®