]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Jan 2026 10:18:41 +0000 (11:18 +0100)
commit68495f89a19b6835e388b89b2ffecc0c68f9666c
tree7474d07eaf5b9b9550e2774c4df001037f55728e
parentfe2401c5d8215b96806f0adbb6f1d4520c46a5b7
selftests/landlock: Fix TCP bind(AF_UNSPEC) test case

[ Upstream commit bd09d9a05cf04028f639e209b416bacaeffd4909 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/landlock/common.h
tools/testing/selftests/landlock/net_test.c