Skip to content

Commit 23c44f6

Browse files
committed
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: ae39ba1 ("perf inject: Fix build ID injection") Reported-by: Linus Torvalds <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Reviewed-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 40384c8 commit 23c44f6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/perf/util/build-id.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int write_buildid(const char *name, size_t name_len, struct build_id *bid
277277
struct perf_record_header_build_id b;
278278
size_t len;
279279

280-
len = sizeof(b) + name_len + 1;
280+
len = name_len + 1;
281281
len = PERF_ALIGN(len, sizeof(u64));
282282

283283
memset(&b, 0, sizeof(b));
@@ -286,7 +286,7 @@ static int write_buildid(const char *name, size_t name_len, struct build_id *bid
286286
misc |= PERF_RECORD_MISC_BUILD_ID_SIZE;
287287
b.pid = pid;
288288
b.header.misc = misc;
289-
b.header.size = len;
289+
b.header.size = sizeof(b) + len;
290290

291291
err = do_write(fd, &b, sizeof(b));
292292
if (err < 0)

0 commit comments

Comments
 (0)