* [PATCH] tracing/probes: clear dynamic data_loc on stage-2 dereference fault
@ 2026-11-26 3:55 Dominik Maier
0 siblings, 0 replies; only message in thread
From: Dominik Maier @ 2026-11-26 3:55 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Mathieu Desnoyers, linux-trace-kernel, dmnk+artist
When recording dynamic probe arguments, store_trace_args() initializes
the first u32 data_loc slot to make_data_loc(maxlen, dyndata - base)
before calling process_fetch_insn().
Commit 797311bce5c2 ("tracing/probes: Fix to record 0-length data_loc in
fetch_store_string*() if fails") removed the ret < 0 fallback in
store_trace_args() so that stage-3 helpers (fetch_store_string*()) would
record a 0-length data_loc per element on string arrays.
However, process_fetch_insn_bottom() can fail earlier in stage 2
(FETCH_OP_DEREF or FETCH_OP_UDEREF) and return immediately before stage
3 runs:
- On a dynamic string array (such as +0(%di):ustring[4]) whose pointer
array faults at or after element 0, returning early from stage 2 aborts
__get_data_size() (dropping space needed by earlier valid elements) and
leaves the remaining u32 data_loc slots uninitialized in
uprobe_cpu_buffer or the ring buffer. When the trace is read,
print_type_string() interprets those stale bytes as a non-zero
(len, offset) pair and reads out of bounds past the copied trace entry.
- On a multi-dereference dynamic string or symstr argument (such as
+0(+0(%si)):ustring), if an intermediate pointer faults in stage 2
after succeeding during __get_data_size(), *dl keeps its pre-set
non-zero maxlen and exposes uninitialized buffer bytes instead of
printing "(fault)".
Formatting a uprobe string array whose pointer table crosses into an
unmapped page triggers a KASAN slab-use-after-free read past iter->ent:
BUG: KASAN: slab-use-after-free in string+0x476/0x570
Read of size 1 at addr ffff88800bb3c948 by task repro_probe_sta/65
Call Trace:
string+0x476/0x570
vsnprintf+0x396/0x1630
seq_buf_vprintf+0x99/0x1e0
trace_seq_printf+0x149/0x370
print_type_string+0xe3/0x130
trace_probe_print_args+0x286/0x3a0
print_uprobe_event+0x1ce/0x3b0
When a stage-2 dereference fails on a dynamic string or symstr argument,
record a 0-length data_loc for that element and continue the
FETCH_OP_LP_ARRAY loop if at the innermost dereference, or clear all
data_loc slots of the argument if an outer dereference fails.
Fixes: 40b53b771806 ("tracing: probeevent: Add array type support")
Fixes: 797311bce5c2 ("tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails")
Cc: stable@vger.kernel.org
Signed-off-by: Dominik Maier <dmnk@google.com>
---
Found with an AI-assisted code review tool (ARTIST) and verified in
QEMU/KVM with KASAN and lockdep against v7.4-rc4 (reproduces the
slab-use-after-free read in print_type_string() before the fix, clean
and preserves valid array elements after); standalone reproducer
available to maintainers on request.
kernel/trace/trace_probe_tmpl.h | 36 ++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
index 8acc0f0..4e0c49a 100644
--- a/kernel/trace/trace_probe_tmpl.h
+++ b/kernel/trace/trace_probe_tmpl.h
@@ -164,8 +164,42 @@ stage2:
lval = llval;
goto out;
}
- if (ret)
+ if (unlikely(ret)) {
+ struct fetch_insn *next = code + 1;
+
+ while (next->op == FETCH_OP_DEREF ||
+ next->op == FETCH_OP_UDEREF ||
+ next->op == FETCH_OP_CPU_PTR)
+ next++;
+
+ if (next->op == FETCH_OP_ST_STRING ||
+ next->op == FETCH_OP_ST_USTRING ||
+ next->op == FETCH_OP_ST_SYMSTR) {
+ if (code + 1 == next) {
+ s3 = next;
+ if (dest) {
+ u32 offs;
+
+ loc = *(u32 *)dest;
+ offs = get_loc_offs(loc);
+ *(u32 *)dest = make_data_loc(0, offs);
+ }
+ code = s3 + 1;
+ goto array;
+ }
+ if (dest) {
+ u32 offs = get_loc_offs(*(u32 *)dest);
+ u32 zloc = make_data_loc(0, offs);
+ int cnt = 1;
+
+ if (next[1].op == FETCH_OP_LP_ARRAY)
+ cnt = next[1].param;
+ for (i = 0; i < cnt; i++)
+ ((u32 *)dest)[i] = zloc;
+ }
+ }
return ret;
+ }
llval = lval;
code++;
} while (1);
base-commit: ebb7a8dc1e74c705daffe11c2faf38ec2628f838
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-26 3:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 3:55 [PATCH] tracing/probes: clear dynamic data_loc on stage-2 dereference fault Dominik Maier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox