mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <jfern@kernel.org>
To: linux-kernel@vger.kernel.org,
	"Paul E . McKenney" <paulmck@kernel.org>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Neeraj Upadhyay" <neeraj.upadhyay@kernel.org>,
	"Joel Fernandes" <jfern@kernel.org>,
	"Josh Triplett" <josh@joshtriplett.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Lai Jiangshan" <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>, "Onur Özkan" <work@onurozkan.dev>
Cc: rcu@vger.kernel.org, Kunwu Chan <kunwu.chan@gmail.com>,
	Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH for-v7.5 05/11] srcu: Validate callback arguments
Date: Thu, 12 Nov 2026 19:50:07 -0500	[thread overview]
Message-ID: <20261113005017.2772440-6-jfern@kernel.org> (raw)
In-Reply-To: <20261113005017.2772440-1-jfern@kernel.org>

From: Kunwu Chan <kunwu.chan@gmail.com>

Check callback-head alignment and reject NULL callback
functions in the SRCU callback registration paths.

Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: Joel Fernandes <jfern@kernel.org>
Signed-off-by: Joel Fernandes <jfern@kernel.org>
---
 kernel/rcu/srcutiny.c | 7 +++++++
 kernel/rcu/srcutree.c | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index 3ee28885b96f..98864977bed2 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -291,6 +291,13 @@ EXPORT_SYMBOL_GPL(srcu_defer_drain);
 void call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
 	       rcu_callback_t func)
 {
+	/* Misaligned rcu_head! */
+	WARN_ON_ONCE((unsigned long)rhp & (sizeof(void *) - 1));
+
+	/* Avoid NULL dereference if callback is NULL. */
+	if (WARN_ON_ONCE(!func))
+		return;
+
 	/* Record the caller: the irq_work's stack says nothing about it. */
 	kasan_record_aux_stack(rhp);
 
diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 46fe2f0cef85..76f074f67299 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1532,6 +1532,13 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
 	if (WARN_ON_ONCE(ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC))
 		return; // Leak the callback rather than corrupt SRCU state.
 
+	/* Misaligned rcu_head! */
+	WARN_ON_ONCE((unsigned long)rhp & (sizeof(void *) - 1));
+
+	/* Avoid NULL dereference if callback is NULL. */
+	if (WARN_ON_ONCE(!func))
+		return;
+
 	/* Record the caller: the irq_work's stack says nothing about it. */
 	kasan_record_aux_stack(rhp);
 
-- 
2.54.0


  parent reply	other threads:[~2026-11-13  0:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  0:50 [PATCH for-v7.5 00/11] RCU debug patches for v7.5 Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 01/11] rcu: Print CPU that preempted stalled reader wants to run on Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 02/11] srcu: Record callback registration stack for KASAN Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 03/11] srcutiny: " Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 04/11] rcu: Record callback registration stack for Tiny RCU Joel Fernandes
2026-11-13  0:50 ` Joel Fernandes [this message]
2026-11-13  0:50 ` [PATCH for-v7.5 06/11] rcu: Validate callback arguments in " Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 07/11] rcu-tasks: Validate callback arguments Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 08/11] srcu: Detect duplicate callback enqueue at registration Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 09/11] srcutiny: Detect duplicate callback enqueue Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 10/11] rcu-tasks: " Joel Fernandes
2026-11-13  0:50 ` [PATCH for-v7.5 11/11] rcu: Improve duplicate callback diagnostics Joel Fernandes

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=20261113005017.2772440-6-jfern@kernel.org \
    --to=jfern@kernel.org \
    --cc=boqun@kernel.org \
    --cc=chentao@kylinos.cn \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=kunwu.chan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.com \
    --cc=work@onurozkan.dev \
    /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®