This is a note to let you know that I've just added the patch titled perf machine: Avoid out of bounds LBR memory read to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: perf-machine-avoid-out-of-bounds-lbr-memory-read.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 94ef4f4326d44d2915eaacff0e2d3e0f557fafa0 Author: Ian Rogers <irogers@xxxxxxxxxx> Date: Tue Oct 24 15:23:05 2023 -0700 perf machine: Avoid out of bounds LBR memory read [ Upstream commit ab8ce150781d326c6bfbe1e09f175ffde1186f80 ] 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: e2b23483eb1d ("perf machine: Factor out lbr_callchain_add_lbr_ip()") Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx> Cc: K Prateek Nayak <kprateek.nayak@xxxxxxx> Cc: Ravi Bangoria <ravi.bangoria@xxxxxxx> Cc: Sandipan Das <sandipan.das@xxxxxxx> Cc: Anshuman Khandual <anshuman.khandual@xxxxxxx> Cc: German Gomez <german.gomez@xxxxxxx> Cc: James Clark <james.clark@xxxxxxx> Cc: Nick Terrell <terrelln@xxxxxx> Cc: Sean Christopherson <seanjc@xxxxxxxxxx> Cc: Changbin Du <changbin.du@xxxxxxxxxx> Cc: liuwenyu <liuwenyu7@xxxxxxxxxx> Cc: Yang Jihong <yangjihong1@xxxxxxxxxx> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx> Cc: Miguel Ojeda <ojeda@xxxxxxxxxx> Cc: Song Liu <song@xxxxxxxxxx> Cc: Leo Yan <leo.yan@xxxxxxxxxx> Cc: Kajol Jain <kjain@xxxxxxxxxxxxx> Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx> Cc: Kan Liang <kan.liang@xxxxxxxxxxxxxxx> Cc: Athira Rajeev <atrajeev@xxxxxxxxxxxxxxxxxx> Cc: Yanteng Si <siyanteng@xxxxxxxxxxx> Cc: Liam Howlett <liam.howlett@xxxxxxxxxx> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx> Link: https://lore.kernel.org/r/20231024222353.3024098-3-irogers@xxxxxxxxxx Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 55a041329990c..a0df9d24b2cb4 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2437,16 +2437,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; }