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: stab…@vger.kernel.org Signed-off-by: Bilal Hashim <AeeS…@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); + } } }