Re: [PATCH] samples: user-trap: fix strict-aliasing warning

From: Kees Cook
Date: Mon Feb 12 2024 - 13:42:42 EST


On Mon, 12 Feb 2024 12:17:31 +0100, Arnd Bergmann wrote:
> I started getting warnings for this one file, though I can't see what changed
> since it was originally introduced in commit fec7b6690541 ("samples: add an
> example of seccomp user trap").
>
> samples/seccomp/user-trap.c: In function 'send_fd':
> samples/seccomp/user-trap.c:50:11: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> 50 | *((int *)CMSG_DATA(cmsg)) = fd;
> | ~^~~~~~~~~~~~~~~~~~~~~~~
> samples/seccomp/user-trap.c: In function 'recv_fd':
> samples/seccomp/user-trap.c:83:18: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> 83 | return *((int *)CMSG_DATA(cmsg));
> | ~^~~~~~~~~~~~~~~~~~~~~~~
>
> [...]

Applied to for-next/seccomp, thanks!

[1/1] samples: user-trap: fix strict-aliasing warning
https://git.kernel.org/kees/c/9ad28ca5238d

Take care,

--
Kees Cook