Skip to contentSkip to conversation

tracepoint-update: do not reuse section pointers from a previous file

PATCH New Leizhen Zhang 1 participant 2 messages Oct 8 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 tracepoint-update: do not reuse section pointers from a previous file

check_data_sec and tracepoint_data_sec are static and set while scanning the section headers in process_tracepoints(), but are never reset. When tracepoint-update is given several files and a later file lacks these sections, the pointers from the previous, already unmapped file are used, which crashes:

  $ scripts/tracepoint-update --module a.o c.o
  AddressSanitizer: SEGV ...

Reset both pointers at the start of process_tracepoints().

Kbuild currently passes a single file per invocation, so this does not affect normal builds.

Fixes e30f8e61e251 ("tracing: Add a tracepoint verification check at build time")
Assisted-by Claude:claude-opus-5-5 ASan UBSan

---
v2:
- Use my real name in the From and Signed-off-by lines. No code changes.

v1: https://lore.kernel.org/r/[email protected]

 scripts/tracepoint-update.c | 4 ++++
 1 file changed, 4 insertions(+)
scripts/tracepoint-update.c +4 -0
index 5cf43c0aac..4c4b669011 100644
@@ -163,6 +163,10 @@ static int process_tracepoints(bool mod, void *addr, const char *fname)
 	int idx;
 	int done = 2;
 
+	/* Do not use the sections of a previously processed file */
+	check_data_sec = NULL;
+	tracepoint_data_sec = NULL;
+
 	shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr));
 	shentsize = ehdr_shentsize(ehdr);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 tracepoint-update: check the section end before reading a string

for_each_shdr_str() evaluates strlen(str) before checking str < end, so after the last string of the section it calls strlen() on the bytes just past the section. Check the bound first.

Fixes e30f8e61e251 ("tracing: Add a tracepoint verification check at build time")
Assisted-by Claude:claude-opus-5-5 ASan

---
v2:
- Use my real name in the From and Signed-off-by lines. No code changes.

v1: https://lore.kernel.org/r/[email protected]

 scripts/tracepoint-update.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/tracepoint-update.c +1 -1
index 4c4b669011..ad5f691c15 100644
@@ -74,7 +74,7 @@ static int add_string(const char *str, const char ***vals, int *count)
 #define for_each_shdr_str(len, ehdr, sec)				\
 	for (const char *str = (void *)(ehdr) + shdr_offset(sec),	\
 			*end = str + shdr_size(sec);			\
-	     len = strlen(str), str < end;				\
+	     str < end && (len = strlen(str), true);			\
 	     str += (len) + 1)
 
 
Signature · 1 line
2.34.1