]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf bpf: Use scnprintf() in snprintf_hex() and synthesize_bpf_prog_name()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 7 Jun 2026 17:23:15 +0000 (14:23 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Jun 2026 18:23:53 +0000 (15:23 -0300)
commitcab3a9331ed0b3f884dd61c8a25b3cf123705982
tree0b25b8cf0713193708bfc2255ba5b697b1fa494e
parentb145137fec13dc8fc7fcb14193ce395a1164e3a1
perf bpf: Use scnprintf() in snprintf_hex() and synthesize_bpf_prog_name()

Both functions accumulate formatted output via ret += snprintf(buf + ret,
size - ret, ...).  If the buffer is too small and snprintf() returns more
than the remaining space, ret exceeds size and the next 'size - ret'
underflows, causing snprintf() to write past the buffer end.

Switch to scnprintf() which returns the actual number of bytes written,
making the accumulation safe.

Fixes: 7b612e291a5affb1 ("perf tools: Synthesize PERF_RECORD_* for loaded BPF programs")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Song Liu <song@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/bpf-event.c