From: Dominik Maier <dmnk@google.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-trace-kernel@vger.kernel.org, dmnk+artist@google.com
Subject: [PATCH] tracing/probes: clear dynamic data_loc on stage-2 dereference fault
Date: Thu, 26 Nov 2026 04:55:56 +0100 [thread overview]
Message-ID: <20261126035556.407947-1-dmnk@google.com> (raw)
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
next reply other threads:[~2026-11-26 3:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 3:55 Dominik Maier [this message]
2026-11-27 13:48 ` [PATCH] tracing/probes: clear dynamic data_loc on stage-2 dereference fault Steven Rostedt
2026-11-30 16:04 ` Dominik Maier
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=20261126035556.407947-1-dmnk@google.com \
--to=dmnk@google.com \
--cc=dmnk+artist@google.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/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.