kernel_samsung_a53x/tools/lib
Jose E. Marchesi 4487ec2968 bpf: Avoid uninitialized value in BPF_CORE_READ_BITFIELD
[ Upstream commit 009367099eb61a4fc2af44d4eb06b6b4de7de6db ]

[Changes from V1:
 - Use a default branch in the switch statement to initialize `val'.]

GCC warns that `val' may be used uninitialized in the
BPF_CRE_READ_BITFIELD macro, defined in bpf_core_read.h as:

	[...]
	unsigned long long val;						      \
	[...]								      \
	switch (__CORE_RELO(s, field, BYTE_SIZE)) {			      \
	case 1: val = *(const unsigned char *)p; break;			      \
	case 2: val = *(const unsigned short *)p; break;		      \
	case 4: val = *(const unsigned int *)p; break;			      \
	case 8: val = *(const unsigned long long *)p; break;		      \
        }       							      \
	[...]
	val;								      \
	}								      \

This patch adds a default entry in the switch statement that sets
`val' to zero in order to avoid the warning, and random values to be
used in case __builtin_preserve_field_info returns unexpected values
for BPF_FIELD_BYTE_SIZE.

Tested in bpf-next master.
No regressions.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240508101313.16662-1-jose.marchesi@oracle.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-19 14:19:41 +01:00
..
api libapi: Add missing linux/types.h header to get the __u64 type on io.h 2024-11-18 12:12:49 +01:00
bpf bpf: Avoid uninitialized value in BPF_CORE_READ_BITFIELD 2024-11-19 14:19:41 +01:00
lockdep Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf libperf evlist: Avoid out-of-bounds access 2024-11-19 09:23:14 +01:00
subcmd libsubcmd: Fix parse-options memory leak 2024-11-19 12:27:05 +01:00
symbol Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
traceevent Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
argv_split.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bitmap.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ctype.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
find_bit.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hweight.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rbtree.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
str_error_r.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
string.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vsprintf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
zalloc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00