]> Git Repo - linux.git/commit
net: dev: Convert sa_data to flexible array in struct sockaddr
authorKees Cook <[email protected]>
Tue, 18 Oct 2022 09:56:03 +0000 (02:56 -0700)
committerJakub Kicinski <[email protected]>
Tue, 25 Oct 2022 18:44:20 +0000 (11:44 -0700)
commitb5f0de6df6dce8d641ef58ef7012f3304dffb9a1
treedd0237be3bc0a9e8e3e67c2254d08fbd8226c8bc
parentd6dd508080a3cdc0ab34ebf66c3734f2dff907ad
net: dev: Convert sa_data to flexible array in struct sockaddr

One of the worst offenders of "fake flexible arrays" is struct sockaddr,
as it is the classic example of why GCC and Clang have been traditionally
forced to treat all trailing arrays as fake flexible arrays: in the
distant misty past, sa_data became too small, and code started just
treating it as a flexible array, even though it was fixed-size. The
special case by the compiler is specifically that sizeof(sa->sa_data)
and FORTIFY_SOURCE (which uses __builtin_object_size(sa->sa_data, 1))
do not agree (14 and -1 respectively), which makes FORTIFY_SOURCE treat
it as a flexible array.

However, the coming -fstrict-flex-arrays compiler flag will remove
these special cases so that FORTIFY_SOURCE can gain coverage over all
the trailing arrays in the kernel that are _not_ supposed to be treated
as a flexible array. To deal with this change, convert sa_data to a true
flexible array. To keep the structure size the same, move sa_data into
a union with a newly introduced sa_data_min with the original size. The
result is that FORTIFY_SOURCE can continue to have no idea how large
sa_data may actually be, but anything using sizeof(sa->sa_data) must
switch to sizeof(sa->sa_data_min).

Cc: Jens Axboe <[email protected]>
Cc: Pavel Begunkov <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Dylan Yudaken <[email protected]>
Cc: Yajun Deng <[email protected]>
Cc: Petr Machata <[email protected]>
Cc: Hangbin Liu <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: syzbot <[email protected]>
Cc: Willem de Bruijn <[email protected]>
Cc: Pablo Neira Ayuso <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
include/linux/socket.h
net/core/dev.c
net/core/dev_ioctl.c
net/packet/af_packet.c
This page took 0.072577 seconds and 4 git commands to generate.