kernel_syms_cmp() subtracts two unsigned long symbol addresses and returns the result as an int. On 64-bit systems this truncates the difference to 32 bits, and on 32-bit systems unsigned differences above INT_MAX become negative. When /proc/kallsyms contains addresses at least 2 GiB apart, such as low per-CPU symbol offsets alongside kernel text and module addresses, the comparator can return the wrong sign or 0 for distinct addresses. This breaks the qsort() ordering of dd->sym_mapping and causes bsearch() in kernel_syms_search() to miss symbols or match the wrong entry. Compare the addresses directly instead of subtracting them, matching cmp_addr_cookie() in link.c. Fixes: 7105e828c087 ("bpf: allow for correlation of maps and helpers in dump") Signed-off-by: Arsalan Yavari --- tools/bpf/bpftool/xlated_dumper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index 5579173a6..d527fdfdf 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c @@ -19,8 +19,11 @@ static int kernel_syms_cmp(const void *sym_a, const void *sym_b) { - return ((struct kernel_sym *)sym_a)->address - - ((struct kernel_sym *)sym_b)->address; + const struct kernel_sym *a = sym_a, *b = sym_b; + + if (a->address == b->address) + return 0; + return a->address < b->address ? -1 : 1; } void kernel_syms_load(struct dump_data *dd) -- 2.54.0 (Apple Git-157)