* [PATCH] libbpf: fix signed multiplication overflow in hash_combine
@ 2024-06-16 22:11 psykose
2024-06-17 2:14 ` Yonghong Song
0 siblings, 1 reply; 2+ messages in thread
From: psykose @ 2024-06-16 22:11 UTC (permalink / raw)
To: bpf
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 <alice@ayaya.dev>
---
src/btf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/btf.c b/src/btf.c
index 2d0840e..60cd412 100644
--- a/src/btf.c
+++ b/src/btf.c
@@ -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
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libbpf: fix signed multiplication overflow in hash_combine
2024-06-16 22:11 [PATCH] libbpf: fix signed multiplication overflow in hash_combine psykose
@ 2024-06-17 2:14 ` Yonghong Song
0 siblings, 0 replies; 2+ messages in thread
From: Yonghong Song @ 2024-06-17 2:14 UTC (permalink / raw)
To: psykose, bpf
On 6/16/24 3:11 PM, psykose wrote:
> 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 <alice@ayaya.dev>
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.
> ---
> src/btf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/btf.c b/src/btf.c
> index 2d0840e..60cd412 100644
> --- a/src/btf.c
> +++ b/src/btf.c
> @@ -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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-17 2:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-16 22:11 [PATCH] libbpf: fix signed multiplication overflow in hash_combine psykose
2024-06-17 2:14 ` Yonghong Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox