From: netdev-bot+sashiko@kernel.org
To: leitao@debian.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
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,
edumazet@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 v2 5/7] ipv4: convert do_ip_getsockopt() to sockopt_t
Date: Sat, 10 Oct 2026 09:12:54 +0000 [thread overview]
Message-ID: <179162357442.434549.2735086321626235140@kernel.org> (raw)
In-Reply-To: <20261009-sockopt_expand_out_v2-v2-5-8ac08c469ecb@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] Undisclosed errno change on calls that already fail.
- [Low] The commit message leaves out two behaviour-relevant parts of the
patch.
--
ipv4: convert do_ip_getsockopt() to sockopt_t
This converts do_ip_getsockopt() and ip_mroute_getsockopt() from a
sockptr_t pair to sockopt_t and removes the IP_MSFILTER and
MCAST_MSFILTER bridges. ip_getsockopt() now builds the sockopt_t with
sockopt_init_user() and always writes optlen back. sol_ip_sockopt()
converts its kernel buffers with sockptr_to_sockopt().
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index d573c5bf8f038..bf00810cdd7a1 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
> @@ -2763,12 +2763,13 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, sockopt_t *opt)
> if (err)
> return err;
>
> - opt->optlen = msf_size;
> if (copy_to_iter(msf, IP_MSFILTER_SIZE(0), &opt->iter_out) !=
> IP_MSFILTER_SIZE(0))
> return -EFAULT;
> if (len && copy_to_iter(psl->sl_addr, len, &opt->iter_out) != len)
> return -EFAULT;
> +
> + opt->optlen = msf_size;
> return 0;
> done:
> return err;
[Severity: Low]
This isn't a bug, but the commit message doesn't explain this hunk. The
move appears to be needed because ip_getsockopt() now always writes
optlen back. The old IP_MSFILTER bridge only wrote it back on success:
err = ip_mc_msfget(sk, &msf, &opt);
if (!err && copy_to_sockptr(optlen, &opt.optlen, sizeof(int)))
err = -EFAULT;
Without the move, a fault while copying the reply would report msf_size
to userspace along with -EFAULT. The previous patch in the series
("ipv4: igmp: convert ip_mc_gsfget() to sockopt_t") explained the same
reasoning for MCAST_MSFILTER. Could this commit message say so as well?
There is also a user-visible fix here that the message doesn't mention.
The old IP_OPTIONS empty path and the old IP_PKTOPTIONS tail in
do_ip_getsockopt() returned the result of copy_to_sockptr() directly:
return copy_to_sockptr(optlen, &len, sizeof(int));
For a user pointer, that result is the number of bytes not copied. So if
optlen was readable but not writable, getsockopt() could return 4
instead of -EFAULT. Now those paths return 0, and put_user() in
ip_getsockopt() turns the failed write into -EFAULT. Would it be worth
noting this in the changelog?
Also, this sentence in the commit message is missing its final period:
ip_getsockopt() builds the sockopt_t with sockopt_init_user() and
writes optlen back unconditionally
> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index 1b7461f1569c3..90d0b5bee68b5 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c
[ ... ]
> @@ -1783,19 +1759,22 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
> int ip_getsockopt(struct sock *sk, int level,
> int optname, char __user *optval, int __user *optlen)
> {
> + sockopt_t opt;
> int err;
>
> - err = do_ip_getsockopt(sk, level, optname,
> - USER_SOCKPTR(optval), USER_SOCKPTR(optlen));
> + err = sockopt_init_user(&opt, optval, optlen);
> + if (err)
> + return err;
> +
> + err = do_ip_getsockopt(sk, level, optname, &opt);
> + if (put_user(opt.optlen, optlen))
> + return -EFAULT;
[Severity: Low]
Reading optlen in sockopt_init_user() before do_ip_getsockopt() runs
seems to change the errno for calls that were already going to fail.
Is that intended?
Before this patch, do_ip_getsockopt() returned before touching optlen in
these cases:
if (level != SOL_IP)
return -EOPNOTSUPP;
if (ip_mroute_opt(optname))
return ip_mroute_getsockopt(sk, optname, optval, optlen);
ip_mroute_getsockopt() did not read optlen either before returning
-EOPNOTSUPP (not a raw IGMP socket), -ENOENT (no mr table) or
-ENOPROTOOPT (unknown MRT_* option).
Any level other than the socket's own protocol level ends up here. For
example, tcp_getsockopt() does:
if (level != SOL_TCP)
return READ_ONCE(icsk->icsk_af_ops)->getsockopt(sk, level,
optname, optval, optlen);
udp_getsockopt() and raw_getsockopt() do the same for levels other than
SOL_UDP and SOL_RAW.
With this patch, getsockopt(tcp4_fd, SOL_IPV6, X, buf, &len) with
len < 0 returns -EINVAL instead of -EOPNOTSUPP. The same applies to an
MRT_* option on a socket that is not raw IGMP. An unreadable optlen
(for example NULL) now returns -EFAULT.
The commit message only describes the unwritable-optlen case. Could it
mention these errno changes too?
The selftest added later in the series ("selftests: net: getsockopt_iter:
cover ip and ipv6") only checks MRT_VERSION returning EOPNOTSUPP with a
valid optlen, so it would not catch this. The code is unchanged at the
end of the series.
Also, these negative checks look unreachable now. In
do_ip_getsockopt():
len = sopt->optlen;
if (len < 0)
return -EINVAL;
and in ip_mroute_getsockopt():
olr = opt->optlen;
if (olr < 0)
return -EINVAL;
Both callers of do_ip_getsockopt() already reject a negative optlen:
ip_getsockopt() through sockopt_init_user() and sol_ip_sockopt()
through sockptr_to_sockopt(). ip_mroute_getsockopt() is only called
from do_ip_getsockopt(). Are these checks still needed?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009-sockopt_expand_out_v2-v2-0-8ac08c469ecb%40debian.org
next prev parent reply other threads:[~2026-10-10 9:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 8:53 [PATCH net-next v2 0/7] ipv4,ipv6: convert the getsockopt switches " Breno Leitao
2026-10-09 8:53 ` [PATCH net-next v2 1/7] ipv6: treat a negative optlen as 4 in do_ipv6_getsockopt() Breno Leitao
2026-10-10 9:12 ` netdev-bot+sashiko
2026-10-09 8:53 ` [PATCH net-next v2 2/7] net: cap sockopt_expand_out() at MAX_RW_COUNT Breno Leitao
2026-10-10 9:12 ` netdev-bot+sashiko
2026-10-09 8:53 ` [PATCH net-next v2 3/7] ipv6: mcast: convert ip6_mc_msfget() to sockopt_t Breno Leitao
2026-10-09 8:53 ` [PATCH net-next v2 4/7] ipv4: igmp: convert ip_mc_gsfget() " Breno Leitao
2026-10-09 8:53 ` [PATCH net-next v2 5/7] ipv4: convert do_ip_getsockopt() " Breno Leitao
2026-10-10 9:12 ` netdev-bot+sashiko [this message]
2026-10-09 8:53 ` [PATCH net-next v2 6/7] ipv6: convert do_ipv6_getsockopt() " Breno Leitao
2026-10-10 9:12 ` netdev-bot+sashiko
2026-10-09 8:53 ` [PATCH net-next v2 7/7] selftests: net: getsockopt_iter: cover ip and ipv6 Breno Leitao
2026-10-10 9:12 ` netdev-bot+sashiko
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=179162357442.434549.2735086321626235140@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@kernel.org \
--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®