BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Breno Leitao" <leitao@debian.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next 4/6] ipv4: convert do_ip_getsockopt() to sockopt_t
Date: Sat, 26 Sep 2026 15:56:30 +0000	[thread overview]
Message-ID: <20260926155631.13E6F1F000FF@smtp.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 1 potential issue(s) to consider:
- [Medium] net: MCAST_MSFILTER leaks modified optlen to userspace on copy failure
--

commit 28c83ba3c12df5eadd41490e34288c12faadfb4f
Author: Breno Leitao <leitao@debian.org>
Subject: ipv4: convert do_ip_getsockopt() to sockopt_t

This commit converts the SOL_IP switch and ip_mroute_getsockopt() to use
sockopt_t. It updates ip_getsockopt() to write optlen back unconditionally,
and modifies ip_mc_msfget() to store its length last so it doesn't report
an updated length if it fails.

> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> --- 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: Medium]
Since put_user() now unconditionally writes opt.optlen back even if
do_ip_getsockopt() returns an error, does this leak modified lengths to
userspace on failure for MCAST_MSFILTER?

The commit message notes that ip_mc_msfget() was changed to store its length
last because of this unconditional writeback. However, the MCAST_MSFILTER
handlers (ip_get_mcast_msfilter() and compat_ip_get_mcast_msfilter()) still
set opt->optlen before their final copy_to_iter() calls.

For example, in 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;

If this final copy fails, do_ip_getsockopt() will return -EFAULT, but the
updated optlen will still be written to userspace.

A similar pattern exists in compat_ip_get_mcast_msfilter():

	opt->optlen = len;
	/* Rewind to gf_fmode, which gf_numsrc follows. */
	iov_iter_revert(&opt->iter_out,
			len - offsetof(struct compat_group_filter, gf_fmode));
	if (copy_to_iter(&gf.gf_fmode, sizeof(gf32.gf_fmode),
			 &opt->iter_out) != sizeof(gf32.gf_fmode) ||
	    copy_to_iter(&gf.gf_numsrc, sizeof(gf32.gf_numsrc),
			 &opt->iter_out) != sizeof(gf32.gf_numsrc))
		return -EFAULT;

Should these handlers also be updated to set opt->optlen only after all
copies have succeeded, matching the change made to ip_mc_msfget()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260925-sockopt_expand_out_v2-v1-0-c3ef2e3bb5c0@debian.org?part=4

  reply	other threads:[~2026-09-26 15:56 UTC|newest]

Thread overview: 17+ 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-29 12:14       ` Breno Leitao
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-26 15:56   ` sashiko-bot [this message]
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

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=20260926155631.13E6F1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leitao@debian.org \
    --cc=sashiko-reviews@lists.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