All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools libbpf: Fix signed shift UB in btf_type_info()
@ 2026-09-03  8:26 liujing
  2026-09-03  8:34 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: liujing @ 2026-09-03  8:26 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Eduard Zingerman, Kumar Kartikeya Dwivedi, bpf, linux-kernel,
	Liu Jing

From: Liu Jing <liujing@cmss.chinamobile.com>

In btf_type_info(), the expression `kflag << 31` performs a signed
integer shift. When kflag is 1, this sets the sign bit of a 32-bit
signed integer, which is undefined behavior in C.

Fix it by casting kflag to unsigned int before the shift.

Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -259,7 +259,7 @@
 
 static inline __u32 btf_type_info(int kind, int vlen, int kflag)
 {
-	return (kflag << 31) | (kind << 24) | vlen;
+	return (((unsigned int)kflag << 31)) | (kind << 24) | vlen;
 }
 
 enum map_def_parts {





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-11 17:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03  8:26 [PATCH] tools libbpf: Fix signed shift UB in btf_type_info() liujing
2026-09-03  8:34 ` sashiko-bot
2026-09-03  9:05 ` bot+bpf-ci
2026-09-11 17:29 ` Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.