Netdev List
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@nvidia.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	David Ahern <dsahern@kernel.org>, Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	syzbot+3d99fb01bcd740f2fc1e@syzkaller.appspotmail.com
Subject: Re: [PATCH v2 net] igmp: convert struct ip_sf_list to RCU
Date: Sun, 30 Aug 2026 12:52:46 +0300	[thread overview]
Message-ID: <20260830095246.GA2771259@shredder> (raw)
In-Reply-To: <20260827160656.903003-1-edumazet@google.com>

On Thu, Aug 27, 2026 at 04:06:56PM +0000, Eric Dumazet wrote:
> Commit 23d2b94043ca ("igmp: Add ip_mc_list lock in ip_check_mc_rcu")
> added spin_lock_bh(&im->lock) to ip_check_mc_rcu() to prevent a
> use-after-free while iterating im->sources during concurrent deletions.
> 
> However, ip_check_mc_rcu() is called from RCU read-side critical
> sections in packet receive and route lookup fast paths (e.g.
> __mkroute_output(), ip_route_input_rcu(), and __udp4_lib_rcv()).
> 
> When igmpv3_send_cr() or igmpv3_send_report() holds &pmc->lock and
> calls add_grec() -> igmpv3_newpack() -> ip_route_output_ports(),
> an XFRM policy matching a multicast destination triggers
> xfrm_tmpl_resolve_one() -> xfrm4_get_saddr() -> __mkroute_output() ->
> ip_check_mc_rcu(). This attempts to acquire &im->lock while &pmc->lock
> is already held on the same CPU, triggering a lockdep recursive locking
> warning / deadlock.
> 
> Fix this by converting IPv4 struct ip_sf_list to RCU, mirroring the
> IPv6 implementation in net/ipv6/mcast.c:
> 
> 1. Add struct rcu_head to struct ip_sf_list and annotate sf_next,
>    sources, and tomb as __rcu pointers.
> 2. Use rcu_assign_pointer() and kfree_rcu() for list updates and
>    deletions.
> 3. Remove spin_lock_bh(&im->lock) from ip_check_mc_rcu() and traverse
>    im->sources locklessly with for_each_psf_rcu(), reading and writing
>    counter fields with READ_ONCE() and WRITE_ONCE().
> 
> Note: RCU conversion of /proc/net/mcfilter will be done in a
> separate patch.
> 
> Fixes: 23d2b94043ca ("igmp: Add ip_mc_list lock in ip_check_mc_rcu")
> Reported-by: syzbot+3d99fb01bcd740f2fc1e@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=3d99fb01bcd740f2fc1e
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

[...]

> @@ -1228,11 +1254,12 @@ static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im,
>  	if (pmc->sfmode == MCAST_INCLUDE) {
>  		struct ip_sf_list *psf;
>  
> +		for_each_psf_mclock(im, psf)
> +			psf->sf_crcount = pmc->crcount;
>  		pmc->tomb = im->tomb;
>  		pmc->sources = im->sources;

In case you need another version:

RCU_INIT_POINTER(pmc->tomb, pmc_dereference(im->tomb, im));
RCU_INIT_POINTER(pmc->sources,
		 pmc_dereference(im->sources, im));

> -		im->tomb = im->sources = NULL;
> -		for (psf = pmc->sources; psf; psf = psf->sf_next)
> -			psf->sf_crcount = pmc->crcount;
> +		RCU_INIT_POINTER(im->tomb, NULL);
> +		RCU_INIT_POINTER(im->sources, NULL);
>  	}
>  	spin_unlock_bh(&im->lock);

[...]

> @@ -2011,19 +2047,28 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
>  
>  		/* no more filters for this source */
>  		if (psf_prev)
> -			psf_prev->sf_next = psf->sf_next;
> +			rcu_assign_pointer(psf_prev->sf_next,
> +					   pmc_dereference(psf->sf_next, pmc));
>  		else
> -			pmc->sources = psf->sf_next;
> +			rcu_assign_pointer(pmc->sources,
> +					   pmc_dereference(psf->sf_next, pmc));
>  #ifdef CONFIG_IP_MULTICAST
>  		if (psf->sf_oldin &&
>  		    !IGMP_V1_SEEN(in_dev) && !IGMP_V2_SEEN(in_dev)) {
> -			psf->sf_crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv);
> -			psf->sf_next = pmc->tomb;
> -			pmc->tomb = psf;
> -			rv = 1;
> -		} else
> +			struct ip_sf_list *dpsf = kmalloc_obj(*dpsf, GFP_ATOMIC);
> +
> +			if (dpsf) {
> +				*dpsf = *psf;
> +				dpsf->sf_crcount = in_dev->mr_qrv ?:
> +					READ_ONCE(net->ipv4.sysctl_igmp_qrv);
> +				rcu_assign_pointer(dpsf->sf_next,
> +						   pmc_dereference(pmc->tomb, pmc));
> +				rcu_assign_pointer(pmc->tomb, dpsf);
> +				rv = 1;
> +			}
> +		}
>  #endif
> -			kfree(psf);
> +		kfree_rcu(psf, rcu);
>  	}
>  	return rv;
>  }

The allocation can fail, but I don't see a better fix. I assume it's
done in that way for the reason mentioned in [1].

[1] https://lore.kernel.org/netdev/20260828084531.1826790-2-edumazet@google.com/

  reply	other threads:[~2026-08-30  9:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 16:06 [PATCH v2 net] igmp: convert struct ip_sf_list to RCU Eric Dumazet
2026-08-30  9:52 ` Ido Schimmel [this message]
2026-09-01  1:00 ` patchwork-bot+netdevbpf

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=20260830095246.GA2771259@shredder \
    --to=idosch@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+3d99fb01bcd740f2fc1e@syzkaller.appspotmail.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