uprobes: Fix NULL pointer dereference in hprobe_expire()
Subsystems (4)
PATCH 1/1 uprobes: Fix NULL pointer dereference in hprobe_expire()
Forking a task that has a pending uretprobe can oops the kernel with a NULL pointer dereference in the clone() path:
BUG: kernel NULL pointer dereference, address: 0000000000000018 Oops: 0002 [#1] SMP NOPTI RIP: 0010:hprobe_expire CR2: 0000000000000018 Call Trace: uprobe_copy_process copy_process kernel_clone __x64_sys_clone do_syscall_64 entry_SYSCALL_64_after_hwframe
This was found on real hosts on Meta fleet.
I've got the impression that this is what is happening:
CPU 1 CPU 2 (traced task)
----- -------------------
hit uprobe, prepare_uretprobe():
hprobe LEASED, refcount >= 1
uprobe_unregister()
put_uprobe(): refcount -> 0
fork() -> dup_utask()
hprobe_expire(hprobe, true)
try_get_uprobe() -> NULL
get_uprobe(NULL) <-- OopsOnly take the extra reference when the uprobe is non-NULL; a NULL means it is gone and is the correct value to return.
--- kernel/events/uprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/uprobes.c +1 -1
@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe; }/*
---
base-commit: 3652b49adac266a3d27cb41cdfdb7d8790fc3633
change-id: 20260729-uprobe-b142b0863572
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
kernel/events/uprobes.c static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get) · line 835
Quoted 9 lines · Breno Leitao
kernel/events/uprobes.c +1
-1@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe;
Well, looks "obviously correct". At least the current code is obviously wrong, it even checks uprobe != NULL 3 lines above.
Andrii ?
Andrii Nakryiko
Acked-byQuoted 15 lines · Oleg Nesterov
kernel/events/uprobes.c static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get) · line 835
Quoted 9 lines · Breno Leitao
kernel/events/uprobes.c +1
-1@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe;Well, looks "obviously correct". At least the current code is obviously wrong, it even checks uprobe != NULL 3 lines above.
Quoted 2 lines
Andrii ?
Yes, indeed, I'm more surprised this didn't come up much earlier (probably it's rare enough to have uretprobe with refcnt at zero during fork). The fix looks good, thanks!
Quoted 3 lines
Acked-by Oleg Nesterov <[email protected]>
Masami Hiramatsu (Google)
maintainerQuoted 16 lines · On Wed, 29 Jul 2026 12:31:08 -0700 Andrii Nakryiko <[email protected]>…
Quoted 15 lines · Oleg Nesterov
kernel/events/uprobes.c static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get) · line 835
Quoted 9 lines · Breno Leitao
kernel/events/uprobes.c +1
-1@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe;Well, looks "obviously correct". At least the current code is obviously wrong, it even checks uprobe != NULL 3 lines above.
Quoted 11 lines
Quoted 2 lines
Andrii ?
Yes, indeed, I'm more surprised this didn't come up much earlier (probably it's rare enough to have uretprobe with refcnt at zero during fork). The fix looks good, thanks!
Acked-by Andrii Nakryiko <[email protected]>Quoted 2 lines
Acked-by Oleg Nesterov <[email protected]>
Thanks, this seems good to me. (uprobe is NULL checked in try_cmpxchg(), so it could be NULL.)
Can I pick this to probes/fixes branch?
Thank you,
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Peter Zijlstra
maintainerQuoted 28 lines · Masami Hiramatsu
Quoted 25 lines · On Wed, 29 Jul 2026 12:31:08 -0700 Andrii Nakryiko <[email protected]>…
Quoted 15 lines · Oleg Nesterov
kernel/events/uprobes.c static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get) · line 835
Quoted 9 lines · Breno Leitao
kernel/events/uprobes.c +1
-1@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe;Well, looks "obviously correct". At least the current code is obviously wrong, it even checks uprobe != NULL 3 lines above.
Quoted 2 lines
Andrii ?
Yes, indeed, I'm more surprised this didn't come up much earlier (probably it's rare enough to have uretprobe with refcnt at zero during fork). The fix looks good, thanks!
Acked-by Andrii Nakryiko <[email protected]>
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Acked-by Oleg Nesterov <[email protected]>Thanks, this seems good to me. (uprobe is NULL checked in
try_cmpxchg(), so it could be NULL.)Can I pick this to probes/fixes branch?
tip/perf/urgent ?
Masami Hiramatsu (Google)
maintainerQuoted 32 lines · On Thu, 30 Jul 2026 12:38:24 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 31 lines · Masami Hiramatsu
Quoted 27 lines · On Wed, 29 Jul 2026 12:31:08 -0700 Andrii Nakryiko <[email protected]>…
Quoted 15 lines · Oleg Nesterov
kernel/events/uprobes.c static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get) · line 835
Quoted 9 lines · Breno Leitao
kernel/events/uprobes.c +1
-1@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe;Well, looks "obviously correct". At least the current code is obviously wrong, it even checks uprobe != NULL 3 lines above.
Quoted 2 lines
Andrii ?
Yes, indeed, I'm more surprised this didn't come up much earlier (probably it's rare enough to have uretprobe with refcnt at zero during fork). The fix looks good, thanks!
Acked-by Andrii Nakryiko <[email protected]>Quoted 2 lines
Acked-by Oleg Nesterov <[email protected]>
Quoted 6 lines
Quoted 4 lines
Thanks, this seems good to me. (uprobe is NULL checked in
try_cmpxchg(), so it could be NULL.)Can I pick this to probes/fixes branch?
tip/perf/urgent ?
Either way works. Can we update MAINTAINERS file if you will maintain uprobe in tip tree?
Thank you,
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Peter Zijlstra
maintainerQuoted 38 lines · Masami Hiramatsu
Quoted 35 lines · On Thu, 30 Jul 2026 12:38:24 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 34 lines · Masami Hiramatsu
Quoted 16 lines · On Wed, 29 Jul 2026 12:31:08 -0700 Andrii Nakryiko <[email protected]>…
Quoted 15 lines · Oleg Nesterov
kernel/events/uprobes.c static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get) · line 835
Quoted 9 lines · Breno Leitao
kernel/events/uprobes.c +1
-1@@ -832,7 +832,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe;Well, looks "obviously correct". At least the current code is obviously wrong, it even checks uprobe != NULL 3 lines above.
Quoted 11 lines
Quoted 2 lines
Andrii ?
Yes, indeed, I'm more surprised this didn't come up much earlier (probably it's rare enough to have uretprobe with refcnt at zero during fork). The fix looks good, thanks!
Acked-by Andrii Nakryiko <[email protected]>Quoted 2 lines
Acked-by Oleg Nesterov <[email protected]>Thanks, this seems good to me. (uprobe is NULL checked in
try_cmpxchg(), so it could be NULL.)
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Can I pick this to probes/fixes branch?
tip/perf/urgent ?
Either way works. Can we update
MAINTAINERSfile if you will maintain uprobe in tip tree?
Well it is in kernel/events/ which MAINTAINERS should already assign to me, no?
Oleg Nesterov
maintainerQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · Masami Hiramatsu
On Thu, 30 Jul 2026 12:38:24 +0200
Either way works. Can we update
MAINTAINERSfile if you will maintain uprobe in tip tree?Well it is in
kernel/events/whichMAINTAINERSshould already assign to me, no?
Confused... you are already listed as a maintainer. From MAINTAINERS:
UPROBES
M: Masami Hiramatsu <[email protected]>
M: Oleg Nesterov <[email protected]>
M: Peter Zijlstra <[email protected]>
L: [email protected]
L: [email protected]
S: Maintained
F: arch/*/include/asm/uprobes.h
F: arch/*/kernel/probes/uprobes.c
F: arch/*/kernel/uprobes.c
F: include/linux/uprobes.h
F: kernel/events/uprobes.c
Oleg.
Peter Zijlstra
maintainerQuoted 13 lines · Oleg Nesterov
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Masami Hiramatsu
On Thu, 30 Jul 2026 12:38:24 +0200
Either way works. Can we update
MAINTAINERSfile if you will maintain uprobe in tip tree?Well it is in
kernel/events/whichMAINTAINERSshould already assign to me, no?Confused... you are already listed as a maintainer. From
MAINTAINERS:
Quoted 12 lines
UPROBES
M: Masami Hiramatsu <[email protected]>
M: Oleg Nesterov <[email protected]>
M: Peter Zijlstra <[email protected]>
L: [email protected]
L: [email protected]
S: Maintained
F:arch/*/include/asm/uprobes.h
F:arch/*/kernel/probes/uprobes.c
F:arch/*/kernel/uprobes.c
F:include/linux/uprobes.h
F:kernel/events/uprobes.c
Yes, but the 'PERFORMANCE EVENTS SUBSYSTEM' entry will also cover this. So I have it twice ;-)
PERFORMANCE EVENTS SUBSYSTEM
...
F: kernel/events/*
Anyway, patch should be in tip/perf/urgent now.
The following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: cc679d7a6303e84d769f2afcde1fc51c51f127cd Gitweb: https://git.kernel.org/tip/cc679d7a6303e84d769f2afcde1fc51c51f127cd Author: Breno Leitao <[email protected]> AuthorDate: Wed, 29 Jul 2026 07:44:40 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 31 Jul 2026 10:32:19 +02:00
uprobes: Fix NULL pointer dereference in hprobe_expire()
Forking a task that has a pending uretprobe can oops the kernel with a NULL pointer dereference in the clone() path:
BUG: kernel NULL pointer dereference, address: 0000000000000018 Oops: 0002 [#1] SMP NOPTI RIP: 0010:hprobe_expire CR2: 0000000000000018 Call Trace: uprobe_copy_process copy_process kernel_clone __x64_sys_clone do_syscall_64 entry_SYSCALL_64_after_hwframe
This was found on real hosts on Meta fleet.
I've got the impression that this is what is happening:
CPU 1 CPU 2 (traced task)
----- -------------------
hit uprobe, prepare_uretprobe():
hprobe LEASED, refcount >= 1
uprobe_unregister()
put_uprobe(): refcount -> 0
fork() -> dup_utask()
hprobe_expire(hprobe, true)
try_get_uprobe() -> NULL
get_uprobe(NULL) <-- OopsOnly take the extra reference when the uprobe is non-NULL; a NULL means it is gone and is the correct value to return.
--- kernel/events/uprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/uprobes.c +1 -1
@@ -830,7 +830,7 @@ static struct uprobe *hprobe_expire(struct hprobe *hprobe, bool get)if (try_cmpxchg (&hprobe->state, &hstate, uprobe ?HPROBE_STABLE :HPROBE_GONE )) {/* We won the race, we are the ones to unlock SRCU */ __srcu_read_unlock (&uretprobes_srcu, hprobe->srcu_idx); -return get ?get_uprobe (uprobe) : uprobe; +return get && uprobe ?get_uprobe (uprobe) : uprobe; }/*