Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Fix build-id event recording

The build-id events written at the end of the record session are broken
due to unexpected data. The write_buildid() writes the fixed length
event first and then variable length filename.

But a recent change made it write more data in the padding area
accidentally. So readers of the event see zero-filled data for the
next entry and treat it incorrectly. This resulted in wrong kernel
symbols because the kernel DSO loaded a random vmlinux image in the
path as it didn't have a valid build-id.

Fixes: ae39ba16554e ("perf inject: Fix build ID injection")
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/Z0aRFFW9xMh3mqKB@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

+2 -2
+2 -2
tools/perf/util/build-id.c
··· 277 277 struct perf_record_header_build_id b; 278 278 size_t len; 279 279 280 - len = sizeof(b) + name_len + 1; 280 + len = name_len + 1; 281 281 len = PERF_ALIGN(len, sizeof(u64)); 282 282 283 283 memset(&b, 0, sizeof(b)); ··· 286 286 misc |= PERF_RECORD_MISC_BUILD_ID_SIZE; 287 287 b.pid = pid; 288 288 b.header.misc = misc; 289 - b.header.size = len; 289 + b.header.size = sizeof(b) + len; 290 290 291 291 err = do_write(fd, &b, sizeof(b)); 292 292 if (err < 0)