mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: leitao@debian.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, kuniyu@google.com,
	willemb@google.com, dsahern@kernel.org, idosch@nvidia.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	david.laight.linux@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH net-next 2/2] ipv4: igmp: convert ip_mc_msfget() to sockopt_t
Date: Sat, 12 Sep 2026 01:19:58 +0000	[thread overview]
Message-ID: <178917599835.219967.6363929586904032206@kernel.org> (raw)
In-Reply-To: <20260910-getsockopt_phase6-v1-2-e681e102d5b8@debian.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider:

Critical: 0 · High: 0 · Medium: 1 · Low: 0

- [Medium] In do_ip_getsockopt() (net/ipv4/ip_sockglue.c, case
  IP_MSFILTER), the output length is now written back to userspace…

--

ipv4: igmp: convert ip_mc_msfget() to sockopt_t

This converts ip_mc_msfget() from the sockptr_t optval/optlen pair to a
sockopt_t built at the do_ip_getsockopt() call site, and replaces the
optval copies with sequential copy_to_iter() calls after growing the
output iterator with sockopt_expand_out().

> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index d56355aca7977..144fca158adcb 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c

[ ... ]

> @@ -2755,14 +2755,19 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
>  	len = flex_array_size(psl, sl_addr, copycount);
>  	msf->imsf_numsrc = count;
>  	msf_size = IP_MSFILTER_SIZE(copycount);
> -	if (copy_to_sockptr(optlen, &msf_size, sizeof(int)) ||
> -	    copy_to_sockptr(optval, msf, IP_MSFILTER_SIZE(0))) {
> +
> +	/* The source list is sized by the imsf_numsrc the caller left in
> +	 * optval, not by optlen, which only has to cover the fixed part.
> +	 */
> +	err = sockopt_expand_out(opt, msf_size);
> +	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_sockptr_offset(optval,
> -				   offsetof(struct ip_msfilter, imsf_slist_flex),
> -				   psl->sl_addr, len))
> +	if (len && copy_to_iter(psl->sl_addr, len, &opt->iter_out) != len)
>  		return -EFAULT;
>  	return 0;
>  done:

> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index a55ef327ec932..c58e565f2a5aa 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c

[ ... ]

> @@ -1715,7 +1717,13 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
>  			err = -EFAULT;
>  			goto out;
>  		}
> -		err = ip_mc_msfget(sk, &msf, optval, optlen);
> +		err = sockptr_to_sockopt(&opt, optval, optlen, &kvec);
> +		if (err)
> +			goto out;
> +
> +		err = ip_mc_msfget(sk, &msf, &opt);
> +		if (copy_to_sockptr(optlen, &opt.optlen, sizeof(int)))
> +			err = -EFAULT;
>  		goto out;

[Severity: Medium]
Should this write-back be guarded by if (!err)?

Before this patch the *optlen store lived inside ip_mc_msfget() and only
ran once the lookup had succeeded:

	msf_size = IP_MSFILTER_SIZE(copycount);
	if (copy_to_sockptr(optlen, &msf_size, sizeof(int)) ||
	    copy_to_sockptr(optval, msf, IP_MSFILTER_SIZE(0))) {
		return -EFAULT;
	}

All of the ip_mc_msfget() failure returns left the user's optlen word
untouched: !ipv4_is_multicast(addr) returning -EINVAL, !in_dev returning
-ENODEV, and the !pmc "must have a prior join" case falling through to
done: with err = -EADDRNOTAVAIL.

Now do_ip_getsockopt() writes opt.optlen back on every return from
ip_mc_msfget(), including those three error paths and the new -EINVAL
from sockopt_expand_out(), since opt->optlen is only assigned on the
success path in ip_mc_msfget(). Is that change of behaviour on failure
intended?

There is a second effect from the missing guard: if the optlen pointer is
readable but not writable, copy_to_sockptr() fails and err is replaced
with -EFAULT, so -EINVAL, -ENODEV and -EADDRNOTAVAIL are no longer
distinguishable by userspace. The earlier copy_from_sockptr(&len, optlen,
...) and the copy_from_sockptr() inside sockptr_to_sockopt() both succeed
on a read-only mapping, so this state is reachable.

Would something like this preserve the old semantics?

	err = ip_mc_msfget(sk, &msf, &opt);
	if (!err && copy_to_sockptr(optlen, &opt.optlen, sizeof(int)))
		err = -EFAULT;

The commit message describes the change as a conversion, with "the bytes
land where they did", and does not mention that the optlen store moved to
the caller and now also runs when ip_mc_msfget() fails. Could that be
called out explicitly?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260910-getsockopt_phase6-v1-0-e681e102d5b8%40debian.org

      parent reply	other threads:[~2026-09-12  1:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  9:47 [PATCH net-next 0/2] net: a sockopt_t quirk for the options that write past optlen Breno Leitao
2026-09-10  9:47 ` [PATCH net-next 1/2] net: add sockopt_expand_out() Breno Leitao
2026-09-11 15:56   ` Stanislav Fomichev
2026-09-11 16:09     ` Breno Leitao
2026-09-11 18:10       ` David Laight
2026-09-11 21:17       ` Stanislav Fomichev
2026-09-12  1:19   ` netdev-bot+sashiko
2026-09-10  9:47 ` [PATCH net-next 2/2] ipv4: igmp: convert ip_mc_msfget() to sockopt_t Breno Leitao
2026-09-11 15:56   ` Stanislav Fomichev
2026-09-12  1:19   ` 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=178917599835.219967.6363929586904032206@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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®