On Mon, Oct 28, 2024 at 09:47:08PM +0100, Johannes Berg wrote: > On Mon, 2024-10-28 at 21:38 +0100, Andrew Lunn wrote: > > > As this new struct will live in UAPI, to avoid breaking user-space code > > > that expects `struct sockaddr`, the `__kernel_sockaddr_legacy` macro is > > > introduced. This macro allows us to use either `struct sockaddr` or > > > `struct sockaddr_legacy` depending on the context in which the code is > > > used: kernel-space or user-space. > > > > Are there cases of userspace API structures where the flexiable array > > appears in the middle? > > Clearly, it's the case for all the three other patches in this series.
The issue is that the kernel uses these structures, and the kernel's view of sockaddr is that it (correctly) has a flexible array. Userspace's view of sockaddr is the old struct (which comes from the libc, not the kernel) which ends with a fake flexible array. We need to correct the kernel's view of these structures to use the introduced legacy struct to avoid lying to the compiler about what's going on. :) -- Kees Cook