Skip to content

Commit 2847f10

Browse files
thesamesampcmoore
authored andcommitted
scmp_bpf_sim: fix aliasing UB
See #425. Punning sys_data_b between uint32_t* and struct* seccomp_data isn't legal, use memcpy to fix the testsuite with Clang 17. Modern compilers recognise this idiom and optimise it out anyway. Signed-off-by: Sam James <[email protected]> Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 5eb0b07 commit 2847f10

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/scmp_bpf_sim.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ static void bpf_execute(const struct bpf_program *prg,
182182
switch (code) {
183183
case BPF_LD+BPF_W+BPF_ABS:
184184
if (k < BPF_SYSCALL_MAX) {
185-
uint32_t val = *((uint32_t *)&sys_data_b[k]);
185+
uint32_t val;
186+
memcpy(&val, &sys_data_b[k], sizeof(val));
186187
state.acc = ttoh32(arch, val);
187188
} else
188189
exit_error(ERANGE, ip_c);

0 commit comments

Comments
 (0)