Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] kprobes: Fix NULL pointer dereference in unregister_kretprobes()
@ 2026-08-05 16:12 Luigi Rizzo
  2026-08-05 18:40 ` Bradley Morgan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Luigi Rizzo @ 2026-08-05 16:12 UTC (permalink / raw)
  To: Masami Hiramatsu, Naveen N Rao, Luigi Rizzo, David S . Miller
  Cc: JP Kobryn, linux-trace-kernel, linux-kernel, Luigi Rizzo

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-08-06 13:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 16:12 [PATCH] kprobes: Fix NULL pointer dereference in unregister_kretprobes() Luigi Rizzo
2026-08-05 18:40 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox