On Mon, 20 Oct 2025 14:26:30 -0700
Kees Cook <[email protected]> wrote:
> Add flexible sockaddr structure to support addresses longer than the
> traditional 14-byte struct sockaddr::sa_data limitation without
> requiring the full 128-byte sa_data of struct sockaddr_storage. This
> allows the network APIs to pass around a pointer to an object that
> isn't lying to the compiler about how big it is, but must be accompanied
> by its actual size as an additional parameter.
>
> It's possible we may way to migrate to including the size with the
> struct in the future, e.g.:
>
> struct sockaddr_unspec {
> u16 sa_data_len;
> u16 sa_family;
> u8 sa_data[] __counted_by(sa_data_len);
> };
One on the historic Unix implementations split the 'sa_family'
field into two single byte fields - the second one containing the length.
That might work - although care would be needed not to pass a length
back to userspace.
NetBSD certainly forbid declaring variables of type 'sockaddr storage',
the kernel could only use pointers to it.
These days that might be enforcable by the compiler.
David