From: sashiko-bot@kernel.org
To: "Yingjie Wang" <x-professor@outlook.com>
Cc: "David Ahern" <dsahern@kernel.org>,
"Ido Schimmel" <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Vladimir Davydov" <vdavydov.dev@gmail.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
tj@kernel.org, mkoutny@suse.com
Subject: Re: [PATCH net 1/3] net: multicast: keep source filter state when a source update fails
Date: Fri, 20 Nov 2026 15:34:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-225467@kernel.org> (raw)
In-Reply-To: <fcc87bc014e01d9571fa33aaabd22180908e55d1.1795102467.git.x-professor@outlook.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: multicast: premature mode switch and stateful rollback
in ip_mc_source()
--
commit 831050a0d77c35ca56da9b5211137601a0a6a62e
Author: Yingjie Wang <x-professor@outlook.com>
net: multicast: keep source filter state when a source update fails
This commit restores the previous socket filter mode, propagates
interface-level source addition errors before publishing the socket filter,
and drops newly created group memberships when a multicast source filter
update fails.
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index 52cde8782eebd..bfa448028f8a1 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
> @@ -2491,9 +2491,10 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
> struct ip_mc_socklist *pmc;
> struct in_device *in_dev = NULL;
> struct inet_sock *inet = inet_sk(sk);
> - struct ip_sf_socklist *psl;
> + struct ip_sf_socklist *newpsl = NULL, *psl;
> struct net *net = sock_net(sk);
> int leavegroup = 0;
> + int oldmode = -1;
> int i, j, rv;
>
> if (!ipv4_is_multicast(addr))
> @@ -2530,9 +2531,10 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
> }
> } else if (pmc->sfmode != omode) {
> /* allow mode switches for empty-set filters */
> + oldmode = pmc->sfmode;
> ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 0, NULL, 0);
> - ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, pmc->sfmode, 0,
> - NULL, 0);
> + ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, oldmode, 0,
> + NULL, 0);
> pmc->sfmode = omode;
> }
[ ... ]
> @@ -2596,26 +2627,19 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
> rcu_assign_pointer(pmc->sflist, newpsl);
> if (psl)
> kfree_rcu(psl, rcu);
> - psl = newpsl;
> - }
> - rv = 1; /* > 0 for insert logic below if sl_count is 0 */
> - for (i = 0; i < psl->sl_count; i++) {
> - rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr,
> - sizeof(__be32));
> - if (rv == 0)
> - break;
> + } else {
> + for (j = psl->sl_count - 1; j >= i; j--)
> + psl->sl_addr[j + 1] = psl->sl_addr[j];
> + psl->sl_addr[i] = mreqs->imr_sourceaddr;
> + psl->sl_count++;
> }
> - if (rv == 0) /* address already there is an error */
> - goto done;
> - for (j = psl->sl_count-1; j >= i; j--)
> - psl->sl_addr[j+1] = psl->sl_addr[j];
> - psl->sl_addr[i] = mreqs->imr_sourceaddr;
> - psl->sl_count++;
> - err = 0;
> - /* update the interface list */
> - ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1,
> - &mreqs->imr_sourceaddr, 1);
> done:
> + if (err && oldmode >= 0) {
> + ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, oldmode, 0,
> + NULL, 0);
> + ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 0, NULL, 0);
> + pmc->sfmode = oldmode;
> + }
[Severity: Medium]
Does switching the empty filter mode up front and rolling it back at done:
still mutate device-level IGMPv3/MLDv2 report state and transiently drop
packets?
When IP_DROP_SOURCE_MEMBERSHIP or MCAST_LEAVE_SOURCE_GROUP (!add) is called
on an empty MCAST_EXCLUDE membership, ip_mc_source() switches the mode to
MCAST_INCLUDE and immediately fails at "if (!psl) goto done;" with
-EADDRNOTAVAIL. If this socket is the only MCAST_EXCLUDE member on the
interface, the upfront ip_mc_del_src() drops sfcount[MCAST_EXCLUDE] to 0
and flips the device-level filter to MCAST_INCLUDE, and the rollback
ip_mc_add_src() at done: flips it back to MCAST_EXCLUDE, zeroing
psf->sf_crcount on all sources for the group, resetting pmc->crcount and
in_dev->mr_ifc_count, and scheduling igmp_ifc_event() to send unsolicited
state-change reports for a failed syscall.
In addition, while pmc->sfmode is set to MCAST_INCLUDE with pmc->sflist ==
NULL (including across the sleeping GFP_KERNEL allocation in sock_kmalloc()
on the add path), lockless RCU readers in ip_mc_sf_allow() see an empty
MCAST_INCLUDE filter and drop incoming multicast packets for the socket.
The same issue exists in ip6_mc_source() in net/ipv6/mcast.c.
Could the empty-filter mode switch be deferred until after validation and
newpsl allocation (where !add with !psl has already been rejected), or
rolled back if the subsequent source addition fails without modifying the
mode before the !add and allocation checks?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795102467.git.x-professor@outlook.com?part=1
next prev parent reply other threads:[~2026-11-20 15:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 15:34 [PATCH net 0/3] net: account socket and multicast allocations to memcg Yingjie Wang
2026-11-19 15:34 ` [PATCH net 1/3] net: multicast: keep source filter state when a source update fails Yingjie Wang
2026-11-20 15:34 ` sashiko-bot [this message]
2026-11-19 15:34 ` [PATCH net 2/3] net: account IPV6_2292PKTOPTIONS and multicast socket state to memcg Yingjie Wang
2026-11-19 15:34 ` [PATCH net 3/3] net: multicast: account group and source allocations " Yingjie Wang
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=sashiko-outbox-225467@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=pabeni@redhat.com \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=vdavydov.dev@gmail.com \
--cc=x-professor@outlook.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