]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/landlock: Fix TCP bind(AF_UNSPEC) test case
authorMatthieu Buffet <matthieu@buffet.re>
Mon, 27 Oct 2025 19:07:24 +0000 (20:07 +0100)
committerMickaël Salaün <mic@digikod.net>
Fri, 26 Dec 2025 19:38:57 +0000 (20:38 +0100)
commitbd09d9a05cf04028f639e209b416bacaeffd4909
treed9a6659dcac9b1fe4b97686318fce7c972aa0088
parente4d82cbce2258f454634307fdabf33aa46b61ab0
selftests/landlock: Fix TCP bind(AF_UNSPEC) test case

The nominal error code for bind(AF_UNSPEC) on an IPv6 socket
is -EAFNOSUPPORT, not -EINVAL. -EINVAL is only returned when
the supplied address struct is too short, which happens to be
the case in current selftests because they treat AF_UNSPEC
like IPv4 sockets do: as an alias for AF_INET (which is a
16-byte struct instead of the 24 bytes required by IPv6
sockets).

Make the union large enough for any address (by adding struct
sockaddr_storage to the union), and make AF_UNSPEC addresses
large enough for any family.

Test for -EAFNOSUPPORT instead, and add a dedicated test case
for truncated inputs with -EINVAL.

Fixes: a549d055a22e ("selftests/landlock: Add network tests")
Signed-off-by: Matthieu Buffet <matthieu@buffet.re>
Link: https://lore.kernel.org/r/20251027190726.626244-2-matthieu@buffet.re
Signed-off-by: Mickaël Salaün <mic@digikod.net>
tools/testing/selftests/landlock/common.h
tools/testing/selftests/landlock/net_test.c