summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorTw <tw19881113@gmail.com>2026-08-28 08:34:10 +0800
committerAndrii Nakryiko <andrii@kernel.org>2026-08-28 10:28:04 -0700
commitcd35e1b10182c42b4ae31ee49119463b17d8ba7f (patch)
treef3414d087af2ebcc7af8855c0c20afc61b259771 /tools/lib
parent5e875ae9e9ffd5c76c6bdf8982f99de340dd46af (diff)
downloadlinux-next-cd35e1b10182c42b4ae31ee49119463b17d8ba7f.tar.gz
linux-next-cd35e1b10182c42b4ae31ee49119463b17d8ba7f.zip
libbpf: Fix for the potential undefined behavior due to shifting
When compiling libbpf with sanitation, ubsan will report the following: ``` left shift of 1 by 31 places cannot be represented in type 'int' ``` This may lead to undefined behavior according to the compiler implementation, let's fix it by casting to unsigned counterpart before shifting. Signed-off-by: Tan Wei <tw19881113@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20260828003448.1684064-1-tw19881113@gmail.com
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.c2
-rw-r--r--tools/lib/bpf/libbpf_internal.h4
2 files changed, 3 insertions, 3 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b749c01742ee..f09cbfd8e729 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11738,7 +11738,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
errstr(bit));
return bit;
}
- attr.config |= 1 << bit;
+ attr.config |= 1ULL << bit;
}
attr.size = attr_sz;
attr.type = type;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 4c46d34fc055..cb4d96233844 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -77,7 +77,7 @@
#define JUMPTABLES_SEC ".jumptables"
#define BTF_INFO_ENC(kind, kind_flag, vlen) \
- ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
+ (((__u32)(!!(kind_flag)) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
#define BTF_TYPE_ENC(name, info, size_or_type) (name), (info), (size_or_type)
#define BTF_INT_ENC(encoding, bits_offset, nr_bits) \
((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
@@ -259,7 +259,7 @@ static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)
static inline __u32 btf_type_info(int kind, int vlen, int kflag)
{
- return (kflag << 31) | (kind << 24) | vlen;
+ return ((__u32)kflag << 31) | (kind << 24) | vlen;
}
enum map_def_parts {