Skip to content

Commit

Permalink
scmp_bpf_sim: fix aliasing UB
Browse files Browse the repository at this point in the history
See seccomp#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]>
  • Loading branch information
thesamesam authored and pcmoore committed Sep 5, 2024
1 parent 5eb0b07 commit 2847f10
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/scmp_bpf_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ static void bpf_execute(const struct bpf_program *prg,
switch (code) {
case BPF_LD+BPF_W+BPF_ABS:
if (k < BPF_SYSCALL_MAX) {
uint32_t val = *((uint32_t *)&sys_data_b[k]);
uint32_t val;
memcpy(&val, &sys_data_b[k], sizeof(val));
state.acc = ttoh32(arch, val);
} else
exit_error(ERANGE, ip_c);
Expand Down

0 comments on commit 2847f10

Please sign in to comment.