mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bradley Morgan <bradley.morgan@linux.dev>
To: yangguikun19@qq.com
Cc: linux-kernel@vger.kernel.org, paulmck@kernel.org, rcu@vger.kernel.org
Subject: Re: [PATCH] srcu: Validate ___srcu_struct_ptrs entries against the module range
Date: Tue, 17 Nov 2026 16:24:52 +0000	[thread overview]
Message-ID: <E089D232-BEB4-4914-A25E-F05033EDD7BD@linux.dev> (raw)
In-Reply-To: <tencent_E038DD9BFA4429F88047A5A4367D578DB80A@qq.com>

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!

      reply	other threads:[~2026-11-17 16:24 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 ` [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 message]

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=E089D232-BEB4-4914-A25E-F05033EDD7BD@linux.dev \
    --to=bradley.morgan@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=yangguikun19@qq.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®