srcu_module_coming() dereferences unvalidated ___srcu_struct_ptrs entries - wild kernel-memory write on module load
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
From: Guikun Yang <[email protected]>
To: "Paul E. McKenney" <[email protected]>
Cc: Luis Chamberlain <[email protected]>, Petr Pavlu <[email protected]>,
[email protected], [email protected], [email protected]
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") = &nameUnlike __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 <[email protected]> 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
From: Guikun Yang <[email protected]>
To: "Paul E. McKenney" <[email protected]>
Cc: Luis Chamberlain <[email protected]>, Petr Pavlu <[email protected]>,
[email protected], [email protected], [email protected]
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") = &nameUnlike __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 <[email protected]> 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
Paul E. McKenney
maintainerQuoted 91 lines · Guikun Yang
From: Guikun Yang <[email protected]>
To: "Paul E. McKenney" <[email protected]>
Cc: Luis Chamberlain <[email protected]>, Petr Pavlu <[email protected]>,
[email protected], [email protected], [email protected]
Subject: [Bug report]srcu_module_coming()dereferences unvalidated
___srcu_struct_ptrsentries - wild kernel-memory write on module loadHi Paul, Luis,
The module loader hands the contents of the
___srcu_struct_ptrssection to SRCU as an array of absolute structsrcu_struct* pointers, with no validation of any entry.srcu_module_coming()then writes through each one during theMODULE_STATE_COMINGnotification, insideinit_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 returnssh_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") = &nameUnlike
__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->sdasits 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()) dereferencesssp->srcu_supand freesssp->sdathrough 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.cvalidates 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()andsrcu_module_going():for (i = 0; i < mod->num_srcu_structs; i++) { ssp = *(sspp++);
Review
Quoted 3 lines
(quoted diff) +2
-0+ 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?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!ssp || !within_module((unsigned long)ssp, mod)) + continue;
Either way, would you be willing to send a proper patch?
Thanx, Paul
Quoted 32 lines
__tracepoints_ptrsand__bpf_raw_tp_mapare sibling pointer sections with the same exposure; a shared check infind_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_offsetbounds gap went out as <[email protected]> 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_modulesize, 11 undefined symbols all matching). A section synthesizer appends an 8-byte___srcu_struct_ptrsentry (0x0000555500000100), fixing shstrtab,e_shnumande_shoff. Same boot, three steps:1. load original xt_mark.ko -> 0 2. unload -> 0 3. load synthesized module -> the Oops aboveThe A/B pair, the synthesizer and the reproducer are available on request.
Tested on 7.3.0;
kernel/rcu/srcutree.cand the loader path are unchanged in mainline as of 2026-11-14.Thanks,
Guikun Yang
PATCH 1/1 srcu: Validate ___srcu_struct_ptrs entries against the module range
In reply to Guikun YangAs 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.
--- kernel/rcu/srcutree.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/rcu/srcutree.c +4 -0
@@ -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);
Signature · 1 line
2.34.1
Re: [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range
Quoted 24 lines · Guikun Yang
As discussed, here is the formal patch. Exactly as you presumed:
srcu_module_going()needs the same check, because a module whosecoming()fails the validation still gets aMODULE_STATE_GOINGnotification via the robust call inprepare_coming_module().---
The entries of the
___srcu_struct_ptrssection are absolute pointers emitted byDEFINE_SRCU()in module .data.load_info()hands the raw section to RCU (kernel/module/main.c), andsrcu_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):
Quoted 6 lines
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, becausegoing()runs even for modules that never passedcoming(), 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.
Quoted 2 lines
Signed-off-by Guikun Yang <[email protected]>
look, makes enough sense
Quoted 20 lines
---
kernel/rcu/srcutree.c| 4 ++++1 file changed, 4 insertions(+)kernel/rcu/srcutree.c +2
-0@@ -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 ;
kernel/rcu/srcutree.c static void srcu_module_going(struct module *mod) · line 2530
Quoted 8 lines
kernel/rcu/srcutree.c +2
-0@@ -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!
Paul E. McKenney
maintainerRe: [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range
In reply to Guikun YangQuoted 6 lines · Guikun Yang
As discussed, here is the formal patch. Exactly as you presumed:
srcu_module_going()needs the same check, because a module whosecoming()fails the validation still gets aMODULE_STATE_GOINGnotification via the robust call inprepare_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
Quoted 55 lines
The entries of the
___srcu_struct_ptrssection are absolute pointers emitted byDEFINE_SRCU()in module .data.load_info()hands the raw section to RCU (kernel/module/main.c), andsrcu_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, becausegoing()runs even for modules that never passedcoming(), and those entries never got per-CPU data allocated.Signed-off-by Guikun Yang <[email protected]>--- kernel/rcu/srcutree.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/rcu/srcutree.c +4
-0@@ -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);Signature · 2 lines
-- 2.34.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
[Bug report] x86-64 apply_returns() decodes attacker-controlled addresses from unvalidated .return_sites entries - wild read on module load
From: Guikun Yang <[email protected]>
To: "Peter Zijlstra (Intel)" <[email protected]>,
Ingo Molnar <[email protected]>,
Arnaldo Carvalho de Melo <[email protected]>
Cc: Luis Chamberlain <[email protected]>, Petr Pavlu <[email protected]>,
Thomas Gleixner <[email protected]>, Borislav Petkov <[email protected]>, Dave Hansen <[email protected]>, [email protected], [email protected], [email protected]
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 <[email protected]>, SRCU pointer section <[email protected]>); 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
Re: [Bug report] x86-64 apply_returns() decodes attacker-controlled addresses from unvalidated .return_sites entries - wild read on module load
Quoted 11 lines · Guikun Yang
From: Guikun Yang <[email protected]>
To: "Peter Zijlstra (Intel)" <[email protected]>,
Ingo Molnar <[email protected]>,
Arnaldo Carvalho de Melo <[email protected]>
Cc: Luis Chamberlain <[email protected]>, Petr Pavlu <[email protected]>,
Thomas Gleixner <[email protected]>, Borislav Petkov <[email protected]>, Dave Hansen <[email protected]>, [email protected], [email protected], [email protected]
Subject: [Bug report] x86-64apply_returns()decodes attacker-controlled
addresses from unvalidated .return_sites entries - wild read on module load
Quoted 6 lines
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 theR_X86_64_PC32relocation 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?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette