Skip to content

Commit a36aeda

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; \ | ^ Fix this by declaring __r to be an array of __u8 of a proper size. 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 b2666a3 commit a36aeda

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tools/lib/bpf/bpf_core_read.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ extern void *bpf_rdonly_cast(const void *obj, __u32 btf_id) __ksym __weak;
517517
* than enough for any practical purpose.
518518
*/
519519
#define BPF_CORE_READ(src, a, ...) ({ \
520-
___type((src), a, ##__VA_ARGS__) __r; \
520+
__u8 __r[sizeof(___type((src), a, ##__VA_ARGS__))]; \
521521
BPF_CORE_READ_INTO(&__r, (src), a, ##__VA_ARGS__); \
522-
__r; \
522+
*(___type((src), a, ##__VA_ARGS__) *)__r; \
523523
})
524524

525525
/*
@@ -533,16 +533,16 @@ extern void *bpf_rdonly_cast(const void *obj, __u32 btf_id) __ksym __weak;
533533
* input argument.
534534
*/
535535
#define BPF_CORE_READ_USER(src, a, ...) ({ \
536-
___type((src), a, ##__VA_ARGS__) __r; \
536+
__u8 __r[sizeof(___type((src), a, ##__VA_ARGS__))]; \
537537
BPF_CORE_READ_USER_INTO(&__r, (src), a, ##__VA_ARGS__); \
538-
__r; \
538+
*(___type((src), a, ##__VA_ARGS__) *)__r; \
539539
})
540540

541541
/* Non-CO-RE variant of BPF_CORE_READ() */
542542
#define BPF_PROBE_READ(src, a, ...) ({ \
543-
___type((src), a, ##__VA_ARGS__) __r; \
543+
__u8 __r[sizeof(___type((src), a, ##__VA_ARGS__))]; \
544544
BPF_PROBE_READ_INTO(&__r, (src), a, ##__VA_ARGS__); \
545-
__r; \
545+
*(___type((src), a, ##__VA_ARGS__) *)__r; \
546546
})
547547

548548
/*
@@ -552,9 +552,9 @@ extern void *bpf_rdonly_cast(const void *obj, __u32 btf_id) __ksym __weak;
552552
* not restricted to kernel types only.
553553
*/
554554
#define BPF_PROBE_READ_USER(src, a, ...) ({ \
555-
___type((src), a, ##__VA_ARGS__) __r; \
555+
__u8 __r[sizeof(___type((src), a, ##__VA_ARGS__))]; \
556556
BPF_PROBE_READ_USER_INTO(&__r, (src), a, ##__VA_ARGS__); \
557-
__r; \
557+
*(___type((src), a, ##__VA_ARGS__) *)__r; \
558558
})
559559

560560
#endif

0 commit comments

Comments
 (0)