* [PATCH] tracing/probes: Zero out faulted dereferenced fields
@ 2026-11-11 10:03 Steven Rostedt
2026-11-11 10:21 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2026-11-11 10:03 UTC (permalink / raw)
To: LKML, Linux trace kernel; +Cc: Masami Hiramatsu, Mathieu Desnoyers
From: Steven Rostedt <rostedt@goodmis.org>
While looking at tasks global descriptor tables, I discovered the
following anomaly:
~# echo 't:sched sched_switch prev=prev mm=(task_struct)prev->mm ppgd=(task_struct)prev->mm->pgd' > /sys/kernel/tracing/dynamic_events
The above creates a tprobe on the sched_switch tracepoint and records the
previous task_struct pointer, it's mm_struct and the pgd the mm_struct
points to.
~# trace-cmd start -e tracepoints:sched
bash-1050 [000] d..3. 90.829478: sched: (__probestub_sched_switch+0x0/0x10) prev=0xffff88d30b623600 mm=0xffff88d30108c600 ppgd=0xffff88d33352b000
<idle>-0 [002] d..3. 90.836024: sched: (__probestub_sched_switch+0x0/0x10) prev=0xffff88d301870000 mm=0x0 ppgd=0x0
rcu_preempt-15 [002] d..3. 90.836031: sched: (__probestub_sched_switch+0x0/0x10) prev=0xffff88d3013ad100 mm=0x0 ppgd=0xffff88d33352b000
The first event has is a user task that has both a valid mm_struct and a pgd.
The second event is a kernel task where the mm_struct is NULL and so is the
dereferenced pgd pointer.
The third event is where things looked strange. The mm_struct is NULL but
the dereferenced pgd has a value! That is: NULL->pgd produced something
other than zero.
The reason for this is that the probe_mem_read() and probe_mem_read_user()
do not write to the destination on failure. The process_fetch_insn_bottom()
loop does not check the return value of the dereference (as it is the last
one), and does not update the event. That leaves the value for that failed
field to be whatever was in the ring buffer at that time.
Have both probe_mem_read() and probe_mem_read_user() set the destination to
zero on failure to read the address.
Now all gdb are zero when mm is zero.
Cc: stable@vger.kernel.org
Fixes: 533059281ee59 ("tracing: probeevent: Introduce new argument fetching code")
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_probe_kernel.h | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h
index 4eb4acfa09ba..00542a162d30 100644
--- a/kernel/trace/trace_probe_kernel.h
+++ b/kernel/trace/trace_probe_kernel.h
@@ -102,18 +102,27 @@ static nokprobe_inline int
probe_mem_read_user(void *dest, void *src, size_t size)
{
const void __user *uaddr = (__force const void __user *)src;
+ int ret;
- return copy_from_user_nofault(dest, uaddr, size);
+ ret = copy_from_user_nofault(dest, uaddr, size);
+ if (ret < 0)
+ memset(dest, 0, size);
+ return ret;
}
static nokprobe_inline int
probe_mem_read(void *dest, void *src, size_t size)
{
+ int ret;
+
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
if ((unsigned long)src < TASK_SIZE)
return probe_mem_read_user(dest, src, size);
#endif
- return copy_from_kernel_nofault(dest, src, size);
+ ret = copy_from_kernel_nofault(dest, src, size);
+ if (ret < 0)
+ memset(dest, 0, size);
+ return ret;
}
#endif /* __TRACE_PROBE_KERNEL_H_ */
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tracing/probes: Zero out faulted dereferenced fields
2026-11-11 10:03 [PATCH] tracing/probes: Zero out faulted dereferenced fields Steven Rostedt
@ 2026-11-11 10:21 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2026-11-11 10:21 UTC (permalink / raw)
To: LKML, Linux trace kernel; +Cc: Masami Hiramatsu, Mathieu Desnoyers
On Wed, 11 Nov 2026 05:03:22 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> Now all gdb are zero when mm is zero.
That's supposed to be: Now all pgd are zero ...
-- Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-11 10:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 10:03 [PATCH] tracing/probes: Zero out faulted dereferenced fields Steven Rostedt
2026-11-11 10:21 ` Steven Rostedt
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®