Skip to content

Commit

Permalink
perf machine: Avoid out of bounds LBR memory read
Browse files Browse the repository at this point in the history
Running perf top with address sanitizer and "--call-graph=lbr" fails
due to reading sample 0 when no samples exist. Add a guard to prevent
this.

Fixes: e2b2348 ("perf machine: Factor out lbr_callchain_add_lbr_ip()")
Signed-off-by: Ian Rogers <[email protected]>
Cc: K Prateek Nayak <[email protected]>
Cc: Ravi Bangoria <[email protected]>
Cc: Sandipan Das <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: German Gomez <[email protected]>
Cc: James Clark <[email protected]>
Cc: Nick Terrell <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Changbin Du <[email protected]>
Cc: liuwenyu <[email protected]>
Cc: Yang Jihong <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Miguel Ojeda <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Leo Yan <[email protected]>
Cc: Kajol Jain <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Athira Rajeev <[email protected]>
Cc: Yanteng Si <[email protected]>
Cc: Liam Howlett <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Namhyung Kim <[email protected]>
  • Loading branch information
captain5050 authored and namhyung committed Oct 25, 2023
1 parent 7a8f349 commit ab8ce15
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2622,16 +2622,18 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
save_lbr_cursor_node(thread, cursor, i);
}

/* Add LBR ip from first entries.to */
ip = entries[0].to;
flags = &entries[0].flags;
*branch_from = entries[0].from;
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, ip,
true, flags, NULL,
*branch_from);
if (err)
return err;
if (lbr_nr > 0) {
/* Add LBR ip from first entries.to */
ip = entries[0].to;
flags = &entries[0].flags;
*branch_from = entries[0].from;
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, ip,
true, flags, NULL,
*branch_from);
if (err)
return err;
}

return 0;
}
Expand Down

0 comments on commit ab8ce15

Please sign in to comment.