[PATCH] stapbpf: Limit remaining sscanf section name widths

Mikhail Dmitrichenko m.dmitrichenko222@gmail.com
Thu Nov 19 09:19:48 GMT 2026


stapbpf accepts a module path on its command line and reads ELF section
names into fixed-size stack buffers using unbounded %s and %[...]
conversions. A malformed module with an overlong section name can corrupt
the stack before any later validation runs. stapbpf is installed setuid
root and executable by the stapusr group, so an unprivileged group member
can supply such a module directly.

The procfs conversion was already limited in upstream commit
91bf95f3a444a. Limit the remaining uprobe, trace, and raw_trace
conversions to one byte less than their destination buffers.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
---
 stapbpf/stapbpf.cxx | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/stapbpf/stapbpf.cxx b/stapbpf/stapbpf.cxx
index 05513757ffa22f3715e172d3b9d1135b7427f0bb..d600ece9b21ad8829ff76048270918f676272bc9 100644
--- a/stapbpf/stapbpf.cxx
+++ b/stapbpf/stapbpf.cxx
@@ -799,7 +799,7 @@ collect_uprobe(const char *name, unsigned name_idx, unsigned fd_idx)
   unsigned long long off = 0;
   char path[PATH_MAX];
 
-  int res = sscanf(name, "uprobe/%c/%d/%llu%s", &type, &pid, &off, path);
+  int res = sscanf(name, "uprobe/%c/%d/%llu%4095s", &type, &pid, &off, path);
 
   if (!pid)
     pid = -1; // indicates to perf_event_open that we're tracing all processes
@@ -860,7 +860,7 @@ collect_tracepoint(const char *name, unsigned name_idx, unsigned fd_idx)
   char tp_system[512];
   char tp_name[512];
 
-  int res = sscanf(name, "trace/%[^/]/%s", tp_system, tp_name);
+  int res = sscanf(name, "trace/%511[^/]/%511s", tp_system, tp_name);
   if (res != 2 || strlen(name) > 512)
     fatal("unable to parse name of probe %u section %u\n", name_idx, fd_idx);
 
@@ -877,7 +877,7 @@ collect_raw_tracepoint(const char *name, unsigned name_idx, unsigned fd_idx)
   char tp_system[512];
   char tp_name[512];
 
-  int res = sscanf(name, "raw_trace/%[^/]/%s", tp_system, tp_name);
+  int res = sscanf(name, "raw_trace/%511[^/]/%511s", tp_system, tp_name);
   if (res != 2 || strlen(name) > 512)
     fatal("unable to parse name of probe %u section %u\n", name_idx, fd_idx);
 
-- 
2.43.0


More information about the Systemtap mailing list