Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/landlock: Add missing connect(minimal AF_UNSPEC) test

connect_variant(unspec_any0) is called twice. Both calls end
up in connect_variant_addrlen() with an address length of
get_addrlen(minimal=false).
However, the connect() syscall and its variants (e.g.
iouring/compat) accept much shorter addresses of 4 bytes
and that behaviour was not tested.

Replace one of these calls with one using a minimal address
length (just a bare sa_family=AF_UNSPEC field with no actual
address). Also add a call using a truncated address for good
measure.

Signed-off-by: Matthieu Buffet <matthieu@buffet.re>
Link: https://lore.kernel.org/r/20251027190726.626244-3-matthieu@buffet.re
Signed-off-by: Mickaël Salaün <mic@digikod.net>

authored by

Matthieu Buffet and committed by
Mickaël Salaün
6685201e bd09d9a0

+13 -1
+13 -1
tools/testing/selftests/landlock/net_test.c
··· 906 906 EXPECT_EQ(0, close(ruleset_fd)); 907 907 } 908 908 909 - ret = connect_variant(connect_fd, &self->unspec_any0); 909 + /* Try to re-disconnect with a truncated address struct. */ 910 + EXPECT_EQ(-EINVAL, 911 + connect_variant_addrlen( 912 + connect_fd, &self->unspec_any0, 913 + get_addrlen(&self->unspec_any0, true) - 1)); 914 + 915 + /* 916 + * Re-disconnect, with a minimal sockaddr struct (just a 917 + * bare af_family=AF_UNSPEC field). 918 + */ 919 + ret = connect_variant_addrlen(connect_fd, &self->unspec_any0, 920 + get_addrlen(&self->unspec_any0, 921 + true)); 910 922 if (self->srv0.protocol.domain == AF_UNIX && 911 923 self->srv0.protocol.type == SOCK_STREAM) { 912 924 EXPECT_EQ(-EINVAL, ret);