[PATCH v2 perf-tools-next 3/6] perf trace: Validate payload bounds in augmented buffer beautifier

From: Aaron Tomlin

Date: Sun Sep 06 2026 - 21:53:39 EST


When pretty-printing non-string augmented buffers via
syscall_arg__scnprintf_buf(), augmented_arg->size is not validated
against the remaining buffer size (arg->augmented.size).

If a malformed or truncated perf.data record provides an invalid or
excessively large augmented_arg->size:
1. If arg->augmented.size is smaller than sizeof(*augmented_arg),
dereferencing augmented_arg->size reads past the available
buffer.

2. The loop reads up to augmented_arg->size bytes from
augmented_arg->value without verifying that they exist within
the buffer, leading to buffer over-reads.

3. Calculating consumed = sizeof(*augmented_arg) +
augmented_arg->size can overflow signed integer bounds or cause
arg->augmented.size to underflow, advancing arg->augmented.args
out of bounds and corrupting the parsing state for subsequent
arguments in multi-argument syscalls.

Validate that arg->augmented.size is large enough to hold
sizeof(*augmented_arg) and that augmented_arg->size is within the bounds
of the remaining buffer before iterating or calculating consumed bytes.
If validation fails, fall back to printing the raw pointer value.

Fixes: b257fac12f38 ("perf trace: Pretty print buffer data")
Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>
---
tools/perf/builtin-trace.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 91461ab927b6..4277de761a54 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1945,13 +1945,17 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg)
{
struct augmented_arg *augmented_arg = arg->augmented.args;
- unsigned char *orig = (unsigned char *)augmented_arg->value;
+ unsigned char *orig;
size_t printed = 0;
int consumed;

- if (augmented_arg == NULL)
- return 0;
+ if (augmented_arg == NULL || arg->augmented.size < (int)sizeof(*augmented_arg))
+ return scnprintf(bf, size, "%#lx", arg->val);
+
+ if (augmented_arg->size <= 0 || augmented_arg->size > arg->augmented.size - (int)sizeof(*augmented_arg))
+ return scnprintf(bf, size, "%#lx", arg->val);

+ orig = (unsigned char *)augmented_arg->value;
for (int j = 0; j < augmented_arg->size; ++j) {
bool control_char = orig[j] <= MAX_CONTROL_CHAR || orig[j] >= MAX_ASCII;
/* print control characters (0~31 and 127), and non-ascii characters in \(digits) */
--
2.55.0