tracepoint-update: do not reuse section pointers from a previous file
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.
---
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
@@ -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
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.
---
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
@@ -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