From: Yuyang Huang <yuyanghuang@google.com>
To: Yuyang Huang <yuyanghuang@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Ido Schimmel <idosch@nvidia.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 1/2] ipv4: igmp: annotate data-races around in_dev->mc_count
Date: Sun, 31 May 2026 11:07:03 +0800 [thread overview]
Message-ID: <20260531030705.3754389-2-yuyanghuang@google.com> (raw)
In-Reply-To: <20260531030705.3754389-1-yuyanghuang@google.com>
/proc/net/igmp walks the multicast list for IPv4 interfaces locklessly
under RCU and prints state->in_dev->mc_count. Concurrently, device
init/destruction and multicast join/leave paths update the count
under the RTNL lock. Fix this intentional lockless snapshot by
annotating the read with READ_ONCE() and the updates with WRITE_ONCE().
Fixes: 1d7138de878d ("igmp: RCU conversion of in_dev->mc_list")
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
---
net/ipv4/igmp.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index f2aca659b29c..fd0faf042fa6 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1566,7 +1566,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
#endif
im->next_rcu = in_dev->mc_list;
- in_dev->mc_count++;
+ WRITE_ONCE(in_dev->mc_count, in_dev->mc_count + 1);
rcu_assign_pointer(in_dev->mc_list, im);
ip_mc_hash_add(in_dev, im);
@@ -1790,7 +1790,8 @@ void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp)
if (new_users == 0) {
ip_mc_hash_remove(in_dev, i);
*ip = i->next_rcu;
- in_dev->mc_count--;
+ WRITE_ONCE(in_dev->mc_count,
+ in_dev->mc_count - 1);
__igmp_group_dropped(i, gfp);
inet_ifmcaddr_notify(in_dev->dev, i,
RTM_DELMULTICAST);
@@ -1922,7 +1923,7 @@ void ip_mc_destroy_dev(struct in_device *in_dev)
while ((i = rtnl_dereference(in_dev->mc_list)) != NULL) {
in_dev->mc_list = i->next_rcu;
- in_dev->mc_count--;
+ WRITE_ONCE(in_dev->mc_count, in_dev->mc_count - 1);
ip_mc_clear_src(i);
ip_ma_put(i);
}
@@ -2974,7 +2975,9 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v)
if (rcu_access_pointer(state->in_dev->mc_list) == im) {
seq_printf(seq, "%d\t%-10s: %5d %7s\n",
- state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier);
+ state->dev->ifindex, state->dev->name,
+ READ_ONCE(state->in_dev->mc_count),
+ querier);
}
delta = im->timer.expires - jiffies;
--
2.54.0.823.g6e5bcc1fc9-goog
next prev parent reply other threads:[~2026-05-31 3:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 3:07 [PATCH net-next 0/2] ipv4: igmp: annotate diagnostic procfs data races Yuyang Huang
2026-05-31 3:07 ` Yuyang Huang [this message]
2026-06-04 9:11 ` [PATCH 1/2] ipv4: igmp: annotate data-races around in_dev->mc_count Paolo Abeni
2026-06-04 9:15 ` Paolo Abeni
2026-06-04 10:17 ` Ido Schimmel
2026-06-04 10:19 ` Ido Schimmel
2026-06-04 11:41 ` Yuyang Huang
2026-05-31 3:07 ` [PATCH 2/2] ipv4: igmp: annotate data-races around timer-related fields Yuyang Huang
2026-06-04 10:20 ` Ido Schimmel
2026-06-04 11:35 ` Yuyang Huang
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=20260531030705.3754389-2-yuyanghuang@google.com \
--to=yuyanghuang@google.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox