Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH net 2/2] ip6mr: Take mrt_lock when filling the output list of a new MFC entry
Date: Fri,  4 Dec 2026 10:48:41 -0800	[thread overview]
Message-ID: <20261204184841.1686426-3-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261204184841.1686426-1-praneethb2002@gmail.com>

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


      parent reply	other threads:[~2026-12-04 18:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261204184841.1686426-1-praneethb2002@gmail.com>
2026-12-04 18:48 ` [PATCH net 1/2] ipmr: Take mrt_lock when filling the output list of a new MFC entry Praneeth Balasubramanian
2026-12-04 18:48 ` Praneeth Balasubramanian [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=20261204184841.1686426-3-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /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