From: Luigi Rizzo <lrizzo@google.com>
To: Masami Hiramatsu <mhiramat@kernel.org>,
Naveen N Rao <naveen@kernel.org>,
Luigi Rizzo <rizzo.unipi@gmail.com>,
"David S . Miller" <davem@davemloft.net>
Cc: JP Kobryn <inwardvessel@gmail.com>,
linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org, Luigi Rizzo <lrizzo@google.com>
Subject: [PATCH] kprobes: Fix NULL pointer dereference in unregister_kretprobes()
Date: Wed, 5 Aug 2026 16:12:21 +0000 [thread overview]
Message-ID: <20260805161221.2428623-1-lrizzo@google.com> (raw)
In unregister_kretprobes(), rps[i]->rph can be NULL e.g. when called
after kretprobe failed registration. Under !CONFIG_KRETPROBE_ON_RETHOOK,
the unconditional access to rps[i]->rph->rp, causes a kernel panic due
to NULL pointer dereference.
Add a NULL check for rps[i]->rph before invoking rcu_assign_pointer().
Fixes: d839a656d0f3 ("kprobes: consistent rcu api usage for kretprobe holder")
Signed-off-by: Luigi Rizzo <lrizzo@google.com>
---
kernel/kprobes.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index bfc89083daa93..5dd4786c455de 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2359,7 +2359,8 @@ void unregister_kretprobes(struct kretprobe **rps, int num)
#ifdef CONFIG_KRETPROBE_ON_RETHOOK
rethook_free(rps[i]->rh);
#else
- rcu_assign_pointer(rps[i]->rph->rp, NULL);
+ if (rps[i]->rph)
+ rcu_assign_pointer(rps[i]->rph->rp, NULL);
#endif
}
--
2.48.1.500.g5897711438-goog
next reply other threads:[~2026-08-05 16:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 16:12 Luigi Rizzo [this message]
2026-08-05 18:40 ` [PATCH] kprobes: Fix NULL pointer dereference in unregister_kretprobes() Bradley Morgan
2026-08-05 20:25 ` JP Kobryn
2026-08-06 0:02 ` Masami Hiramatsu
2026-08-06 7:23 ` Luigi Rizzo
2026-08-06 13:41 ` Masami Hiramatsu
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=20260805161221.2428623-1-lrizzo@google.com \
--to=lrizzo@google.com \
--cc=davem@davemloft.net \
--cc=inwardvessel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=naveen@kernel.org \
--cc=rizzo.unipi@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.