From: Bilal Hashim <AeeSec@126.com>
To: Jiri Pirko <jiri@resnulli.us>, Andrew Lunn <andrew+netdev@lunn.ch>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] net: team: wait for RCU grace period before rehashing tx ports
Date: Mon, 30 Nov 2026 16:52:19 +0800 [thread overview]
Message-ID: <179602873965.13688.342290887566008585@126.com> (raw)
In __reconstruct_port_hlist(), when a TX-enabled team port is disabled
or removed, every subsequent TX-enabled port is unlinked from
team->tx_en_port_hlist with hlist_del_rcu(&port->tx_hlist) and
immediately re-inserted into another hash bucket with
hlist_add_head_rcu(&port->tx_hlist, ...) without waiting for an RCU
grace period.
Reusing port->tx_hlist immediately after hlist_del_rcu() overwrites
its next pointer while concurrent TX softirq readers in
team_get_port_by_tx_index_rcu() may still be traversing the previous
bucket under rcu_read_lock(). This can cause RCU readers to jump to
another bucket, miss active ports, or loop indefinitely in TX softirq.
All callers of __reconstruct_port_hlist() run in sleepable process
context under team->lock. Unlink all affected ports first, wait for a
single RCU grace period with synchronize_rcu() if any ports are being
rehashed, and then update their tx_index and re-insert them into the
hash table.
Found by manual code inspection.
Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
Cc: stable@vger.kernel.org
Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
drivers/net/team/team_core.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c
index 65ac25e..44deeb1 100644
--- a/drivers/net/team/team_core.c
+++ b/drivers/net/team/team_core.c
@@ -1017,15 +1017,27 @@ static void __reconstruct_port_hlist(struct team *team, int rm_index)
{
struct hlist_head *tx_port_index_hash;
struct team_port *port;
- int i;
+ bool moved = false;
+
+ list_for_each_entry(port, &team->port_list, list) {
+ if (port->tx_index > rm_index) {
+ hlist_del_rcu(&port->tx_hlist);
+ moved = true;
+ }
+ }
- for (i = rm_index + 1; i < team->tx_en_port_count; i++) {
- port = team_get_port_by_tx_index(team, i);
- hlist_del_rcu(&port->tx_hlist);
- WRITE_ONCE(port->tx_index, port->tx_index - 1);
- tx_port_index_hash = team_tx_port_index_hash(team,
- port->tx_index);
- hlist_add_head_rcu(&port->tx_hlist, tx_port_index_hash);
+ if (!moved)
+ return;
+
+ synchronize_rcu();
+
+ list_for_each_entry(port, &team->port_list, list) {
+ if (port->tx_index > rm_index) {
+ WRITE_ONCE(port->tx_index, port->tx_index - 1);
+ tx_port_index_hash = team_tx_port_index_hash(team,
+ port->tx_index);
+ hlist_add_head_rcu(&port->tx_hlist, tx_port_index_hash);
+ }
}
}
reply other threads:[~2026-11-30 8:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=179602873965.13688.342290887566008585@126.com \
--to=aeesec@126.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jiri@resnulli.us \
--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