Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/2] ipmr, ip6mr: Take mrt_lock when filling the output list of a new MFC entry
@ 2026-12-04 18:48 Praneeth Balasubramanian
  2026-12-04 18:48 ` [PATCH net 1/2] ipmr: " Praneeth Balasubramanian
  2026-12-04 18:48 ` [PATCH net 2/2] ip6mr: " Praneeth Balasubramanian
  0 siblings, 2 replies; 3+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:48 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, David Ahern, Ido Schimmel, Kuniyuki Iwashima,
	netdev, linux-kernel, Praneeth Balasubramanian

ipmr_update_thresholds() and ip6mr_update_thresholds() read the VIF/MIF
table and are documented to run under mrt_lock. Both MFC add functions
take the lock for an existing entry but not for a new one. That was fine
while MFC and VIF/MIF updates were all serialized by RTNL. The MFC paths
now use dedicated mutexes: IPv4 rtnetlink since commit bddafc06ca5e
("ipmr: Don't hold RTNL for ipmr_rtm_route().") and IPv6 setsockopt
since commit a4c98421720a ("ip6mr: Replace RTNL with a dedicated mutex
for MFC."). So a new entry can be filled from a table that changes
during the scan.

Patch 1 fixes IPv4 and patch 2 IPv6. They are split because the Fixes
commits landed in different releases (v7.1 and v7.2).

Found by a static analysis tool (Clang context analysis on the locking
rule in the comment); the IPv6 twin was then found by inspection. Not
triggered; build-tested only.

Praneeth Balasubramanian (2):
  ipmr: Take mrt_lock when filling the output list of a new MFC entry
  ip6mr: Take mrt_lock when filling the output list of a new MFC entry

 net/ipv4/ipmr.c  | 2 ++
 net/ipv6/ip6mr.c | 2 ++
 2 files changed, 4 insertions(+)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net 1/2] ipmr: Take mrt_lock when filling the output list of a new MFC entry
  2026-12-04 18:48 [PATCH net 0/2] ipmr, ip6mr: Take mrt_lock when filling the output list of a new MFC entry Praneeth Balasubramanian
@ 2026-12-04 18:48 ` Praneeth Balasubramanian
  2026-12-04 18:48 ` [PATCH net 2/2] ip6mr: " Praneeth Balasubramanian
  1 sibling, 0 replies; 3+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:48 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, David Ahern, Ido Schimmel, Kuniyuki Iwashima,
	netdev, linux-kernel, Praneeth Balasubramanian, stable

ipmr_update_thresholds() reads mrt->maxvif and mrt->vif_table[] to fill
the output interface list of an MFC entry. Its comment says that it is
called under mrt_lock, which vif_add() and vif_delete() hold while they
change these fields. ipmr_mfc_add() takes mrt_lock when it updates an
existing entry, but not when it fills a new one.

This was fine while every caller of ipmr_mfc_add() held RTNL, like the
VIF updates do. Since commit bddafc06ca5e ("ipmr: Don't hold RTNL for
ipmr_rtm_route()."), an RTM_NEWROUTE request for RTNL_FAMILY_IPMR holds
only net->ipv4.mfc_mutex, which MRT_ADD_VIF and MRT_DEL_VIF do not take.
A new entry can then be filled from a VIF table that changes during the
scan, and its output list may match no VIF configuration that ever
existed. Traffic for the group is then dropped, or later forwarded
through a VIF index that was reused.

Take mrt_lock around ipmr_update_thresholds() for a new entry too.

This was discovered by a static analysis tool: Clang context analysis
checking the locking rule in the comment of ipmr_update_thresholds()
(an LLM was used to turn the comment into a rule). The issue was not
triggered, and the fix was only build-tested.

Fixes: bddafc06ca5e ("ipmr: Don't hold RTNL for ipmr_rtm_route().")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by a compiler-based check, part of research at UCSB SecLab.
    The locking rule stated in the kernel-doc comment of the called function
    was turned into a Clang context-analysis requirement (__must_hold) on that
    function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
    caller. An LLM was used only to turn the comment into a machine-readable
    rule; the report itself comes from the compiler. The patch and changelog
    were drafted with Claude Opus 5.5. I reviewed the patch and take
    responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64, clang 23,
    allmodconfig). Not runtime-tested, and I have not observed the race
    myself.

 net/ipv4/ipmr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index edb6038ce956..969d5fd9f053 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1305,7 +1305,9 @@ static int ipmr_mfc_add(struct net *net, struct mr_table *mrt,
 	c->mfc_origin = mfc->mfcc_origin.s_addr;
 	c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr;
 	c->_c.mfc_parent = mfc->mfcc_parent;
+	spin_lock(&mrt_lock);
 	ipmr_update_thresholds(mrt, &c->_c, mfc->mfcc_ttls);
+	spin_unlock(&mrt_lock);
 	if (!mrtsock)
 		c->_c.mfc_flags |= MFC_STATIC;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH net 2/2] ip6mr: Take mrt_lock when filling the output list of a new MFC entry
  2026-12-04 18:48 [PATCH net 0/2] ipmr, ip6mr: Take mrt_lock when filling the output list of a new MFC entry Praneeth Balasubramanian
  2026-12-04 18:48 ` [PATCH net 1/2] ipmr: " Praneeth Balasubramanian
@ 2026-12-04 18:48 ` Praneeth Balasubramanian
  1 sibling, 0 replies; 3+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:48 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, David Ahern, Ido Schimmel, Kuniyuki Iwashima,
	netdev, linux-kernel, Praneeth Balasubramanian, stable

ip6mr_update_thresholds() reads mrt->maxvif and mrt->vif_table[] to
fill the output interface list of an MFC entry. Its comment says that it
is called under mrt_lock, which mif6_add() and mif6_delete() hold while
they change these fields. ip6mr_mfc_add() takes mrt_lock when it updates
an existing entry, but not when it fills a new one.

This was fine while MRT6_ADD_MFC held RTNL, like MRT6_ADD_MIF and
MRT6_DEL_MIF do. Since commit a4c98421720a ("ip6mr: Replace RTNL with a
dedicated mutex for MFC."), MRT6_ADD_MFC holds only
net->ipv6.mfc_mutex, which the MIF updates do not take. A new entry can
then be filled from a MIF table that changes during the scan, and its
output list may match no MIF configuration that ever existed. Traffic
for the group is then dropped, or later forwarded through a MIF index
that was reused.

Take mrt_lock around ip6mr_update_thresholds() for a new entry too.

This was discovered by a static analysis tool: Clang context analysis
checking the locking rule in the comment of the IPv4 twin,
ipmr_update_thresholds() (an LLM was used to turn the comment into a
rule); the IPv6 path was then found by code inspection. The issue was
not triggered, and the fix was only build-tested.

Fixes: a4c98421720a ("ip6mr: Replace RTNL with a dedicated mutex for MFC.")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by a compiler-based check, part of research at UCSB SecLab.
    The locking rule stated in the kernel-doc comment of the called function
    was turned into a Clang context-analysis requirement (__must_hold) on that
    function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
    caller. An LLM was used only to turn the comment into a machine-readable
    rule; the report itself comes from the compiler. The patch and changelog
    were drafted with Claude Opus 5.5. I reviewed the patch and take
    responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64, clang 23,
    allmodconfig). Not runtime-tested, and I have not observed the race
    myself.

 net/ipv6/ip6mr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index abe2116704c5..cfd864c538a8 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1524,7 +1524,9 @@ static int ip6mr_mfc_add(struct net *net, struct mr_table *mrt,
 	c->mf6c_origin = mfc->mf6cc_origin.sin6_addr;
 	c->mf6c_mcastgrp = mfc->mf6cc_mcastgrp.sin6_addr;
 	c->_c.mfc_parent = mfc->mf6cc_parent;
+	spin_lock(&mrt_lock);
 	ip6mr_update_thresholds(mrt, &c->_c, ttls);
+	spin_unlock(&mrt_lock);
 	if (!mrtsock)
 		c->_c.mfc_flags |= MFC_STATIC;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:48 [PATCH net 0/2] ipmr, ip6mr: Take mrt_lock when filling the output list of a new MFC entry Praneeth Balasubramanian
2026-12-04 18:48 ` [PATCH net 1/2] ipmr: " Praneeth Balasubramanian
2026-12-04 18:48 ` [PATCH net 2/2] ip6mr: " Praneeth Balasubramanian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox