libbpf: fix signed multiplication overflow in hash_combine
PATCH 1/1 libbpf: fix signed multiplication overflow in hash_combine
when using -fsanitize=undefined (which flags signed overflow which is UB), a crash can be reproduced when building the linux kernel with BTF info.
cast to unsigned first to make the overflow not invoke UB semantics- the result is the same.
--- src/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/btf.c +1 -1
@@ -3317,7 +3317,7 @@ struct btf_dedup {static long hash_combine (long h,long value) { -return h *31 + value; +return (long )((unsigned long )h *31 + (unsigned long )value); }#define for_each_dedup_cand (d, node, hash) \
base-commit: 42065ea6627ff6e1ab4c65e51042a70fbf30ff7c
Signature · 1 line
2.45.2
Yonghong Song
reviewerQuoted 8 lines · psykose
when using -fsanitize=undefined (which flags signed overflow which is UB), a crash can be reproduced when building the linux kernel with BTF info.
cast to unsigned first to make the overflow not invoke UB semantics- the result is the same.
Signed-off-by psykose <[email protected]>
This seems against upstream libbpf repo. Could you do a proper patch against bpf-next tree. Please have details how to reproduce the failure.
Please use proper name in your Signed-off-by.
Quoted 19 lines
--- src/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/btf.c +1
-1@@ -3317,7 +3317,7 @@ struct btf_dedup {static long hash_combine (long h,long value) { -return h *31 + value; +return (long )((unsigned long )h *31 + (unsigned long )value); }#define for_each_dedup_cand (d, node, hash) \base-commit:
42065ea6627ff6e1ab4c65e51042a70fbf30ff7c