diff options
author | Kuan-Wei Chiu <[email protected]> | 2024-12-09 21:42:26 +0800 |
---|---|---|
committer | Namhyung Kim <[email protected]> | 2024-12-09 13:54:08 -0800 |
commit | 246dfe3dc199246bd64635163115f2691623fc53 (patch) | |
tree | 5bd0f5e4f408a698a01bab442b4bcc35538c7cac /tools/testing/selftests/bpf/prog_tests/prog_array_init.c | |
parent | c33aea446bf555ab2b4e06deb914ba8f87cdb068 (diff) |
perf ftrace: Fix undefined behavior in cmp_profile_data()
The comparison function cmp_profile_data() violates the C standard's
requirements for qsort() comparison functions, which mandate symmetry
and transitivity:
* Symmetry: If x < y, then y > x.
* Transitivity: If x < y and y < z, then x < z.
When v1 and v2 are equal, the function incorrectly returns 1, breaking
symmetry and transitivity. This causes undefined behavior, which can
lead to memory corruption in certain versions of glibc [1].
Fix the issue by returning 0 when v1 and v2 are equal, ensuring
compliance with the C standard and preventing undefined behavior.
Link: https://www.qualys.com/2024/01/30/qsort.txt [1]
Fixes: 0f223813edd0 ("perf ftrace: Add 'profile' command")
Fixes: 74ae366c37b7 ("perf ftrace profile: Add -s/--sort option")
Cc: [email protected]
Signed-off-by: Kuan-Wei Chiu <[email protected]>
Reviewed-by: Namhyung Kim <[email protected]>
Reviewed-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Namhyung Kim <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/prog_array_init.c')
0 files changed, 0 insertions, 0 deletions