Skip to content

Commit ea205b4

Browse files
aspskKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
bpf: fix uninitialized values in BPF_{CORE,PROBE}_READ
With the latest LLVM bpf selftests build will fail with the following error message: progs/profiler.inc.h:710:31: error: default initialization of an object of type 'typeof ((parent_task)->real_cred->uid.val)' (aka 'const unsigned int') leaves the object uninitialized and is incompatible with C++ [-Werror,-Wdefault-const-init-unsafe] 710 | proc_exec_data->parent_uid = BPF_CORE_READ(parent_task, real_cred, uid.val); | ^ tools/testing/selftests/bpf/tools/include/bpf/bpf_core_read.h:520:35: note: expanded from macro 'BPF_CORE_READ' 520 | ___type((src), a, ##__VA_ARGS__) __r; \ | ^ This happens because BPF_CORE_READ (and other macro) declare the variable __r using the ___type macro which can inherit const modifier from intermediate types. Fix this by using __typeof_unqual__, when supported. (And when it is not supported, the problem shouldn't appear, as older compilers haven't complained.) Fixes: 792001f ("libbpf: Add user-space variants of BPF_CORE_READ() family of macros") Fixes: a4b09a9 ("libbpf: Add non-CO-RE variants of BPF_CORE_READ() macro family") Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
1 parent 6bce87f commit ea205b4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/lib/bpf/bpf_core_read.h

+6
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,13 @@ extern void *bpf_rdonly_cast(const void *obj, __u32 btf_id) __ksym __weak;
388388
#define ___arrow10(a, b, c, d, e, f, g, h, i, j) a->b->c->d->e->f->g->h->i->j
389389
#define ___arrow(...) ___apply(___arrow, ___narg(__VA_ARGS__))(__VA_ARGS__)
390390

391+
#if defined(__clang__) && (__clang_major__ >= 19)
392+
#define ___type(...) __typeof_unqual__(___arrow(__VA_ARGS__))
393+
#elif defined(__GNUC__) && (__GNUC__ >= 14)
394+
#define ___type(...) __typeof_unqual__(___arrow(__VA_ARGS__))
395+
#else
391396
#define ___type(...) typeof(___arrow(__VA_ARGS__))
397+
#endif
392398

393399
#define ___read(read_fn, dst, src_type, src, accessor) \
394400
read_fn((void *)(dst), sizeof(*(dst)), &((src_type)(src))->accessor)

0 commit comments

Comments
 (0)