[PATCH] perf evsel: fix buffer offset when building the EPERM error string
From: Gu Bin
Date: Wed Nov 04 2026 - 05:40:55 EST
When building the EPERM error string, the scnprintf() that emits "No
permission to enable %s event" uses (msg, size) instead of (msg +
printed, size - printed) like every other line in this case, overwriting
the "Access to performance monitoring..." preamble and truncating the
following hint. The message shown to the user for a failed open with
EPERM is therefore garbled: the preamble is lost and stale bytes from
the overwritten content remain in the buffer.
Use the correct offset and remaining size.
Fixes: c1034eb06920 ("perf tool: Make perf tool aware of SELinux access control")
Signed-off-by: Gu Bin <gubin@xxxxxxxxxxxxxxxxxxxx>
---
tools/perf/util/evsel.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d060fca8090f..6d69f63b7fb1 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -4590,7 +4590,7 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
}
if (err == EPERM)
- printed += scnprintf(msg, size,
+ printed += scnprintf(msg + printed, size - printed,
"No permission to enable %s event.\n\n", evsel__name(evsel));
return printed + scnprintf(msg + printed, size - printed,
--
2.55.0.windows.3