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
Date: Sat, 14 Nov 2026 10:00:00 +0800 [thread overview]
Message-ID: <tencent_3923A965DF3923C24E79A60851533EB55108@qq.com> (raw)
In-Reply-To: <mod-r-offset-oob-20261113@qq.com>
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
next parent reply other threads:[~2026-11-13 17:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mod-r-offset-oob-20261113@qq.com>
2026-11-14 2:00 ` Guikun Yang [this message]
[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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_3923A965DF3923C24E79A60851533EB55108@qq.com \
--to=yangguikun19@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-rcu@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=paulmck@kernel.org \
--cc=petr.pavlu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®