mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: leitao@debian.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
	john.fastabend@gmail.com, sdf@fomichev.me, shuah@kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	david.laight.linux@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH net-next 6/6] selftests: net: getsockopt_iter: cover ip and ipv6
Date: Mon, 28 Sep 2026 18:55:51 +0000	[thread overview]
Message-ID: <179062175174.3145.17201750089772911183@kernel.org> (raw)
In-Reply-To: <20260925-sockopt_expand_out_v2-v1-6-c3ef2e3bb5c0@debian.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The ipv6 fixture does not test the SOL_IPV6 length handling that
  the commit message describes.
- [Low] FIXTURE_SETUP(ipv6) sets IPV6_HOPOPTS and SKIPs the whole fixture
  if that fails.
- [Low] ip.mroute_wrong_type and ipv6.mroute_wrong_type read ENOPROTOOPT
  as "CONFIG_IP_MROUTE / CONFIG_IPV6_MROUTE disabled" and SKIP.
- [Low] The "roundtrip" and clamp tests check only return codes and
  lengths, not the data that comes back.

--

selftests: net: getsockopt_iter: cover ip and ipv6

This adds ip and ipv6 fixtures to the getsockopt_iter selftest. They
check the returned length and errno across buffer sizes, the branches
that answer empty, an unknown optname, and the MRT options dispatched
before the main switch.

> diff --git a/tools/testing/selftests/net/getsockopt_iter.c b/tools/testing/selftests/net/getsockopt_iter.c
> index 6c2408df46123..32b6e0a50f1f9 100644
> --- a/tools/testing/selftests/net/getsockopt_iter.c
> +++ b/tools/testing/selftests/net/getsockopt_iter.c

[ ... ]

> @@ -492,6 +499,301 @@ TEST_F(rawv6, bad_optname)

[ ... ]

> +/* The MRT_* options are dispatched ahead of the rest of the switch and
> + * want a raw IGMP socket. Without CONFIG_IP_MROUTE they are not
> + * dispatched at all and the switch answers ENOPROTOOPT instead.
> + */
> +TEST_F(ip, mroute_wrong_type)
> +{
> +	socklen_t optlen = sizeof(int);
> +	int val;
> +
> +	ASSERT_EQ(-1, getsockopt(self->fd, SOL_IP, MRT_VERSION, &val,
> +				 &optlen));
> +	if (errno == ENOPROTOOPT)
> +		SKIP(return, "CONFIG_IP_MROUTE disabled");
> +	ASSERT_EQ(EOPNOTSUPP, errno);
> +}

[Severity: Low]
Can this SKIP hide a regression in the early MRT dispatch? A kernel with
CONFIG_IP_MROUTE=n returns ENOPROTOOPT here. A kernel where a conversion
dropped or reordered this dispatch returns the same errno:

net/ipv4/ip_sockglue.c:do_ip_getsockopt() {
    ...
	if (ip_mroute_opt(optname))
		return ip_mroute_getsockopt(sk, optname, sopt);
    ...
}

Without that dispatch, MRT_VERSION falls through to the default case and
gets -ENOPROTOOPT. ip_getsockopt() then skips the nf_getsockopt() fallback,
because !ip_mroute_opt(optname) is false. The test sees ENOPROTOOPT and
skips.

ipv6.mroute_wrong_type does the same for the ip6_mroute_opt() dispatch in
do_ipv6_getsockopt(). There, nf_getsockopt() also answers ENOPROTOOPT for an
unknown optname.

tools/testing/selftests/net/config sets CONFIG_IPV6_MROUTE=y. So on a CI
kernel, the IPv6 skip would hide a real regression.

Could the tests tell these two cases apart, rather than treating every
ENOPROTOOPT as a config skip?

[ ... ]

> +FIXTURE_SETUP(ipv6)
> +{
> +	/* an 8 byte hop-by-hop header, so the sticky options answer */
> +	static const unsigned char hopopt[8] = { 0, 0, 1, 4, 0, 0, 0, 0 };
> +	int hops = 42;
> +
> +	self->fd = socket(AF_INET6, SOCK_DGRAM, 0);
> +	if (self->fd < 0)
> +		SKIP(return, "AF_INET6 dgram socket: %s", strerror(errno));
> +
> +	if (setsockopt(self->fd, SOL_IPV6, IPV6_UNICAST_HOPS, &hops,
> +		       sizeof(hops)) < 0)
> +		SKIP(return, "set IPV6_UNICAST_HOPS: %s", strerror(errno));
> +
> +	if (setsockopt(self->fd, SOL_IPV6, IPV6_HOPOPTS, hopopt,
> +		       sizeof(hopopt)) < 0)
> +		SKIP(return, "set IPV6_HOPOPTS: %s", strerror(errno));
> +}

[Severity: Low]
Does this make the whole ipv6 fixture skip without CAP_NET_RAW? The
IPV6_HOPOPTS setsockopt is privileged:

net/ipv6/ipv6_sockglue.c:ipv6_set_opt_hdr() {
    ...
	/* hop-by-hop / destination options are privileged option */
	if (optname != IPV6_RTHDR && !sockopt_ns_capable(net->user_ns, CAP_NET_RAW))
		return -EPERM;
    ...
}

When that returns EPERM, all nine ipv6 tests skip. Six of them never use
the sticky header: hops_exact, hops_oversize_clamped, pathmtu_undersize,
pktoptions_wrong_type, mroute_wrong_type and bad_optname. hopopts_absent
opens its own socket, so it doesn't use the header either.

The ip fixture sets a router alert IP_OPTIONS, which needs no capability.
So the two fixtures behave differently under the same privileges.

Could the IPV6_HOPOPTS setup move into the hopopts tests that need it?

[ ... ]

> +TEST_F(ipv6, hops_exact)
> +{
> +	socklen_t optlen = sizeof(int);
> +	int val = 0;
> +
> +	ASSERT_EQ(0, getsockopt(self->fd, SOL_IPV6, IPV6_UNICAST_HOPS, &val,
> +				&optlen));
> +	ASSERT_EQ(sizeof(int), optlen);
> +	ASSERT_EQ(42, val);
> +}
> +
> +TEST_F(ipv6, hops_oversize_clamped)
> +{
> +	socklen_t optlen = 64;
> +	char buf[64] = {};
> +
> +	ASSERT_EQ(0, getsockopt(self->fd, SOL_IPV6, IPV6_UNICAST_HOPS, buf,
> +				&optlen));
> +	ASSERT_EQ(sizeof(int), optlen);
> +}

[Severity: Low]
The commit message says:

    SOL_IP answers a sub-int buffer with one byte where SOL_IPV6 clamps the
    int.

ip.ttl_single_byte covers the SOL_IP half. Is there an ipv6 test for the
other half? The ipv6 fixture only has hops_exact and hops_oversize_clamped.
Nothing matches ip.ttl_single_byte, ip.ttl_zero_len or ip.negative_optlen.

So no test runs the clamping tail of do_ipv6_getsockopt() with a sub-int
buffer:

net/ipv6/ipv6_sockglue.c:do_ipv6_getsockopt() {
    ...
	len = min_t(unsigned int, sizeof(int), len);
	sopt->optlen = len;
    ...
}

An earlier patch in this series, "ipv6: reject a negative optlen in
do_ipv6_getsockopt()", added a negative optlen rejection. It now lives in
sockopt_init_user(), called from ipv6_getsockopt(), and nothing here tests
it.

rawv6.hdrincl_undersize_clamped doesn't reach this path either.
rawv6_getsockopt() sends IPV6_HDRINCL to do_rawv6_getsockopt() instead.

Would it make sense to add sub-int, zero-length and negative optlen cases
for IPV6_UNICAST_HOPS?

> +
> +TEST_F(ipv6, hopopts_roundtrip)
> +{
> +	unsigned char buf[64] = {};
> +	socklen_t optlen = sizeof(buf);
> +
> +	ASSERT_EQ(0, getsockopt(self->fd, SOL_IPV6, IPV6_HOPOPTS, buf,
> +				&optlen));
> +	ASSERT_EQ(8, optlen);
> +}
> +
> +TEST_F(ipv6, hopopts_undersize_clamped)
> +{
> +	unsigned char buf[4] = {};
> +	socklen_t optlen = sizeof(buf);
> +
> +	ASSERT_EQ(0, getsockopt(self->fd, SOL_IPV6, IPV6_HOPOPTS, buf,
> +				&optlen));
> +	ASSERT_EQ(sizeof(buf), optlen);
> +}

[Severity: Low]
Should these tests compare buf against hopopt[]? Both only check optlen.
ipv6_getsockopt_sticky() copies the data separately from returning the
length:

	len = min_t(unsigned int, len, ipv6_optlen(hdr));
	if (copy_to_iter(hdr, len, &sopt->iter_out) != len)
		return -EFAULT;
	return len;

A conversion that copied the wrong bytes, or skipped the copy entirely,
would still pass as long as the length was right.

The IPv4 tests have a similar gap. ip.options_roundtrip only checks
buf[0] == 0x94, and ignores the length byte and the value bytes of
ipopts[]. ip.options_undersize_clamped only checks the length. In both
cases the data comes from the copy_to_iter() of opt->__data in
do_ip_getsockopt().

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260925-sockopt_expand_out_v2-v1-0-c3ef2e3bb5c0%40debian.org

      reply	other threads:[~2026-09-28 18:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 15:55 [PATCH net-next 0/6] ipv4,ipv6: convert the getsockopt switches to sockopt_t Breno Leitao
2026-09-25 15:55 ` [PATCH net-next 1/6] ipv6: reject a negative optlen in do_ipv6_getsockopt() Breno Leitao
2026-09-25 19:02   ` Stanislav Fomichev
2026-09-27  6:53     ` David Laight
2026-09-28 18:55   ` netdev-bot+sashiko
2026-09-25 15:55 ` [PATCH net-next 2/6] ipv6: mcast: convert ip6_mc_msfget() to sockopt_t Breno Leitao
2026-09-28 18:55   ` netdev-bot+sashiko
2026-09-25 15:55 ` [PATCH net-next 3/6] ipv4: igmp: convert ip_mc_gsfget() " Breno Leitao
2026-09-28 18:55   ` netdev-bot+sashiko
2026-09-25 15:55 ` [PATCH net-next 4/6] ipv4: convert do_ip_getsockopt() " Breno Leitao
2026-09-28 18:55   ` netdev-bot+sashiko
2026-09-25 15:55 ` [PATCH net-next 5/6] ipv6: convert do_ipv6_getsockopt() " Breno Leitao
2026-09-28 18:55   ` netdev-bot+sashiko
2026-09-25 15:55 ` [PATCH net-next 6/6] selftests: net: getsockopt_iter: cover ip and ipv6 Breno Leitao
2026-09-28 18:55   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179062175174.3145.17201750089772911183@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=emil@etsalapatis.com \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®