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 4/6] ipv4: convert do_ip_getsockopt() to sockopt_t
Date: Mon, 28 Sep 2026 18:55:47 +0000 [thread overview]
Message-ID: <179062174764.3145.7414686101186998778@kernel.org> (raw)
In-Reply-To: <20260925-sockopt_expand_out_v2-v1-4-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 conversion quietly fixes a bug where getsockopt() could
return a positive value, but the commit message does not mention it…
Pre-existing issues:
- [Low] ip_get_mcast_msfilter() and compat_ip_get_mcast_msfilter() in
net/ipv4/ip_sockglue.c set opt->optlen (to gsf_size or len) before…
--
ipv4: convert do_ip_getsockopt() to sockopt_t
This patch moves do_ip_getsockopt() and ip_mroute_getsockopt() from a
sockptr_t optval/optlen 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 to userspace.
sol_ip_sockopt() in net/core/filter.c builds a kernel sockopt_t with
sockptr_to_sockopt().
> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index 1f452b6ea86e9..2e78b11d294a9 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c
[ ... ]
> @@ -1620,16 +1618,15 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
> rcu_read_unlock();
>
> if (opt->optlen == 0) {
> - len = 0;
> - return copy_to_sockptr(optlen, &len, sizeof(int));
> + sopt->optlen = 0;
> + return 0;
> }
[ ... ]
> @@ -1680,8 +1677,8 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
> int tos = READ_ONCE(inet->rcv_tos);
> put_cmsg(&msg, SOL_IP, IP_TOS, sizeof(tos), &tos);
> }
> - len -= msg.msg_controllen;
> - return copy_to_sockptr(optlen, &len, sizeof(int));
> + sopt->optlen = len - msg.msg_controllen;
> + return 0;
> }
[Severity: Low]
This isn't a bug, but the commit message doesn't mention that these two
branches also change the getsockopt() return value.
Before this patch, the empty IP_OPTIONS branch and the IP_PKTOPTIONS tail
both ended with:
return copy_to_sockptr(optlen, &len, sizeof(int));
For a user optlen, copy_to_sockptr() returns the copy_to_user() count of
bytes not copied, not -EFAULT.
Take an optlen on a page that is readable but not writable (for example
PROT_READ). The earlier copy_from_sockptr(&len, optlen, ...) succeeds, the
write fails, and do_ip_getsockopt() returns +4. That value passes back
through this chain:
do_sock_getsockopt()
-> sock_common_getsockopt()
-> udp_getsockopt() / tcp_getsockopt()
-> ip_getsockopt()
-> do_ip_getsockopt()
As a result, getsockopt(2) returns 4.
With this patch, both branches only set sopt->optlen, and the put_user()
in ip_getsockopt() returns -EFAULT. That looks correct.
Could this be mentioned in the commit message? Another option is a separate
patch with a Fixes: tag, so stable can pick it up.
[ ... ]
> @@ -1711,43 +1707,25 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
[ ... ]
> case MCAST_MSFILTER:
> - {
> - struct kvec kvec;
> - sockopt_t opt;
> -
> - err = sockptr_to_sockopt(&opt, optval, optlen, &kvec);
> - if (err)
> - goto out;
> -
> if (in_compat_syscall())
> - err = compat_ip_get_mcast_msfilter(sk, &opt);
> + err = compat_ip_get_mcast_msfilter(sk, sopt);
> else
> - err = ip_get_mcast_msfilter(sk, &opt);
> - if (!err && copy_to_sockptr(optlen, &opt.optlen, sizeof(int)))
> - err = -EFAULT;
> + err = ip_get_mcast_msfilter(sk, sopt);
> goto out;
> - }
[Severity: Low]
This is a pre-existing issue, but it now shows up again. With the !err
guard gone and the unconditional write-back in ip_getsockopt():
err = do_ip_getsockopt(sk, level, optname, &opt);
if (put_user(opt.optlen, optlen))
return -EFAULT;
MCAST_MSFILTER can return -EFAULT after it has already changed the user's
optlen. ip_get_mcast_msfilter() sets the length before its last copy:
net/ipv4/ip_sockglue.c:ip_get_mcast_msfilter() {
...
opt->optlen = gsf_size;
/* ip_mc_gsfget() consumed the whole reply; rewind to the fixed part. */
iov_iter_revert(&opt->iter_out, gsf_size);
if (copy_to_iter(&gsf, size0, &opt->iter_out) != size0)
return -EFAULT;
...
}
compat_ip_get_mcast_msfilter() does the same thing: it sets
opt->optlen = len before the gf_fmode and gf_numsrc copy_to_iter() calls.
One trigger is an optval that is readable but not writable. The
copy_from_iter() of the header succeeds, then the header copy_to_iter()
fails.
The pre-series code already wrote optlen before the optval copy in these
helpers. So the end result matches the original behaviour, and only
reverses the !err guard from the previous patch, "ipv4: igmp: convert
ip_mc_gsfget() to sockopt_t". The IPv6 conversion later in the series
(ipv6_get_msfilter() and compat_ipv6_get_msfilter()) uses the same
set-then-copy order.
This patch does move ip_mc_msfget() to store its length last, though. So
IP_MSFILTER and MCAST_MSFILTER now act differently when the final copy
faults.
Should ip_get_mcast_msfilter() and compat_ip_get_mcast_msfilter() also
set opt->optlen after their copies, to match ip_mc_msfget()?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260925-sockopt_expand_out_v2-v1-0-c3ef2e3bb5c0%40debian.org
next prev parent 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 " 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 [this message]
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
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=179062174764.3145.7414686101186998778@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®