From: Ido Schimmel <idosch@nvidia.com>
To: netdev-bot+sashiko@kernel.org
Cc: 18983559317@163.com, dsahern@kernel.org, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] igmp: use copy-on-write RCU updates in ip_mc_source()
Date: Mon, 23 Nov 2026 20:33:30 +0200 [thread overview]
Message-ID: <20261123183330.GA3587849@shredder> (raw)
In-Reply-To: <179543961529.3135.8092538762905615997@kernel.org>
On Mon, Nov 23, 2026 at 01:13:35PM +0000, netdev-bot+sashiko@kernel.org wrote:
> > @@ -2556,13 +2556,33 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
> > goto done;
> > }
> >
> > + atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
> > + &sk->sk_omem_alloc);
> > + if (psl->sl_count == 1) {
> > + newpsl = NULL;
>
> [Severity: Low]
> Is this change in setsockopt behaviour intended? When the last source is
> removed from an MCAST_EXCLUDE filter, this now publishes NULL into
> pmc->sflist. The old code shifted the entries in place and left a non-NULL
> list with sl_count == 0. The MCAST_INCLUDE case with one source becomes
> leavegroup before it gets here.
>
> The mode check at the top of ip_mc_source() only allows a mode switch
> when sflist is NULL:
>
> if (pmc->sflist) {
> if (pmc->sfmode != omode) {
> err = -EINVAL;
> goto done;
> }
> } else if (pmc->sfmode != omode) {
> /* allow mode switches for empty-set filters */
>
> Take this sequence: IP_ADD_MEMBERSHIP, IP_BLOCK_SOURCE S,
> IP_UNBLOCK_SOURCE S, then IP_ADD_SOURCE_MEMBERSHIP S2. The last call used
> to fail with -EINVAL. It now succeeds and switches the group to
> MCAST_INCLUDE with S2.
>
> This matches what ip_mc_msfilter() and ip6_mc_source() already do.
> ip_mc_sf_allow() also treats a NULL MCAST_EXCLUDE list and an empty one
> the same way.
>
> Since this is a Fixes: tagged data race fix, should the commit message
> mention the change?
No. The Fixes tag will be removed in v3 and there's no need to mention
this. The change is fine and consistent with the IPv6 counterpart,
ip6_mc_source().
>
> > + } else {
> > + newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr,
> > + psl->sl_count - 1), GFP_KERNEL);
> > + if (!newpsl) {
> > + atomic_add(struct_size(psl, sl_addr, psl->sl_max),
> > + &sk->sk_omem_alloc);
> > + err = -ENOBUFS;
> > + goto done;
> > + }
>
> [Severity: Low]
> Can removing a source now fail with -ENOBUFS? Before this patch,
> IP_DROP_SOURCE_MEMBERSHIP, IP_UNBLOCK_SOURCE, MCAST_LEAVE_SOURCE_GROUP and
> MCAST_UNBLOCK_SOURCE always succeeded once the source was found.
>
> The old list's charge is subtracted first, so the optmem check usually
> passes. However, sock_kmalloc() reads optmem_max at call time:
>
> int optmem_max = READ_ONCE(sock_net(sk)->core.sysctl_optmem_max);
>
> if ((unsigned int)size <= optmem_max &&
> atomic_read(&sk->sk_omem_alloc) + size < optmem_max) {
>
> This allocation can fail in two cases:
>
> - optmem_max was lowered below the socket's other option memory use
> - the GFP_KERNEL allocation fails for a large list
>
> In either case userspace cannot drop a single source, and an
> MCAST_EXCLUDE block stays in force.
>
> The error path itself restores the accounting cleanly. The workarounds
> are IP_MSFILTER with zero sources or leaving the group.
> ip6_mc_source() can fail the same way.
Noise.
>
> > + newpsl->sl_max = psl->sl_count - 1;
> > + newpsl->sl_count = psl->sl_count - 1;
>
> [ ... ]
>
> > @@ -2572,49 +2592,52 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
> > err = -ENOBUFS;
> > goto done;
> > }
> > - if (!psl || psl->sl_count == psl->sl_max) {
> > - struct ip_sf_socklist *newpsl;
> > - int count = IP_SFBLOCK;
>
> [ ... ]
>
> > + i = psl ? psl->sl_count + 1 : 1;
> > + count = IP_SFBLOCK;
> > + if (psl)
> > + count += psl->sl_max;
> > + newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, count),
> > + GFP_KERNEL);
> > + if (!newpsl) {
> > + err = -ENOBUFS;
> > + goto done;
> > + }
> > + newpsl->sl_max = count;
> > + newpsl->sl_count = i;
>
> [Severity: Medium]
> Does sl_max now grow by IP_SFBLOCK on every add? The old code only
> reallocated when sl_count == sl_max, so the spare slots were filled
> before the list grew.
>
> Now a new list is allocated on every add, but it is still sized as the
> old sl_max plus IP_SFBLOCK. The spare slots are never used:
>
> add 1: sl_count = 1, sl_max = 10
> add 2: sl_count = 2, sl_max = 20
> add 3: sl_count = 3, sl_max = 30
>
> After N adds the buffer has room for about 10*N entries instead of N.
>
> The old list's charge is only removed after the new allocation succeeds:
>
> if (psl) {
> /* decrease mem now to avoid the memleak warning */
> atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
> &sk->sk_omem_alloc);
> }
>
> So both oversized buffers have to fit under optmem_max in sock_kmalloc()
> at the same time.
>
> Assume the default optmem_max of 128 KiB and a raised igmp_max_msf. In
> that case IP_ADD_SOURCE_MEMBERSHIP, IP_BLOCK_SOURCE and
> MCAST_JOIN_SOURCE_GROUP start returning -ENOBUFS at about 1600 sources
> per group, compared with about 16000 before. Large lists also become
> high-order allocations.
>
> With the default igmp_max_msf of 10, sl_max stays at or below 100.
>
> The delete path in this patch and ip_mc_msfilter() size the new list
> exactly. So does ip6_mc_source() in net/ipv6/mcast.c:
>
> i = psl ? psl->sl_count + 1 : 1;
> newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, i),
> GFP_KERNEL);
> ...
> newpsl->sl_max = i;
> newpsl->sl_count = i;
>
> Should the IPv4 add path use struct_size(newpsl, sl_addr, i) and
> sl_max = i as well?
Already mentioned in my reply.
prev parent reply other threads:[~2026-11-23 18:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 12:51 [PATCH net v2] igmp: use copy-on-write RCU updates in ip_mc_source() Binbin Deng
2026-11-22 14:44 ` Ido Schimmel
2026-11-23 13:13 ` netdev-bot+sashiko
2026-11-23 18:33 ` Ido Schimmel [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=20261123183330.GA3587849@shredder \
--to=idosch@nvidia.com \
--cc=18983559317@163.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.