From: Linkui Xiao <xiaolinkui@126.com>
To: Paul Moore <paul@paul-moore.com>, netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, James Morris <jmorris@namei.org>,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, Linkui Xiao <xiaolinkui@kylinos.cn>
Subject: [PATCH net] netlabel: fix a race in netlbl_unlhsh_condremove_iface()
Date: Fri, 27 Nov 2026 17:23:24 +0800 [thread overview]
Message-ID: <20261127092325.3563681-1-xiaolinkui@126.com> (raw)
From: Linkui Xiao <xiaolinkui@kylinos.cn>
netlbl_unlhsh_condremove_iface() unlinks an interface entry and queues it
for freeing without checking ->valid, so it can do both a second time for
an entry that somebody else has already removed.
netlbl_unlhsh_remove() looks the entry up under RCU, drops the lock,
removes the address entry and only then calls condremove_iface(). If a
NETDEV_DOWN notifier runs in between it takes netlbl_unlhsh_lock, clears
->valid and does list_del_rcu() plus call_rcu() on the same entry, and
nothing serialises the notifier against a STATICREMOVE doit, which only
holds genl_lock. The second list_del_rcu() then dereferences the
LIST_POISON2 that the first one left in ->prev, and the second call_rcu()
queues an rcu_head that is already queued, so the entry is freed twice.
The default entry can hit the same thing without any notifier: smackfs
reaches netlbl_unlhsh_remove() through netlbl_cfg_unlbl_static_del() and
is not serialised against a concurrent STATICREMOVEDEF, so two callers can
each remove one address from the same entry and both find it empty.
Check ->valid before unlinking, the way netlbl_unlhsh_netdev_handler() and
netlbl_domhsh_remove_entry() already do. Everything that invalidates an
entry does so under netlbl_unlhsh_lock, so the check is reliable.
Fixes: 8cc44579d1bd ("NetLabel: Introduce static network labels for unlabeled connections")
Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
---
net/netlabel/netlabel_unlabeled.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index 47bae5e48db6..d73c27b0c9d0 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -582,6 +582,8 @@ static void netlbl_unlhsh_condremove_iface(struct netlbl_unlhsh_iface *iface)
#endif /* IPv6 */
spin_lock(&netlbl_unlhsh_lock);
+ if (!iface->valid)
+ goto unlhsh_condremove_failure;
netlbl_af4list_foreach_rcu(iter4, &iface->addr4_list)
goto unlhsh_condremove_failure;
#if IS_ENABLED(CONFIG_IPV6)
--
2.25.1
next reply other threads:[~2026-11-27 9:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 9:23 Linkui Xiao [this message]
2026-11-27 9:23 ` [PATCH net] netlabel: fix duplicate IPv4 entries in the staticlist dump Linkui Xiao
2026-11-27 9:30 ` netdev-bot+sinfo
2026-11-27 9:30 ` [PATCH net] netlabel: fix a race in netlbl_unlhsh_condremove_iface() netdev-bot+sinfo
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=20261127092325.3563681-1-xiaolinkui@126.com \
--to=xiaolinkui@126.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jmorris@namei.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paul@paul-moore.com \
--cc=xiaolinkui@kylinos.cn \
/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