bpf/btf: fix u32 subtraction overflow in btf_sec_info_cmp
PATCH 1/1 bpf/btf: fix u32 subtraction overflow in btf_sec_info_cmp
The comparison function btf_sec_info_cmp() uses direct subtraction of u32 values cast to int, which can produce incorrect results due to integer overflow when values exceed 0x7FFFFFFF.
Replace with explicit comparisons to guarantee correct behavior across all u32 value ranges.
Reported-by Ibrahim Zein <[email protected]>
Signed-off-by Ibrahim Zein <[email protected]>
--- kernel/bpf/btf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/btf.c +5 -1
@@ -5548,7 +5548,11 @@ static int btf_sec_info_cmp(const void *a, const void *b)const struct btf_sec_info *x = a;const struct btf_sec_info *y = b; -return (int )(x->off - y->off) ? : (int )(x->len - y->len); +if (x->off != y->off) +return x->off < y->off ?-1 :1 ; +if (x->len != y->len) +return x->len < y->len ?-1 :1 ; +return 0 ; } static int btf_check_sec_info(struct btf_verifier_env *env,
Signature · 1 line
2.51.0