hsr: Avoid double remove of a node.

[ Upstream commit 0c74d9f79ec4299365bbe803baa736ae0068179e ]

Due to the hashed-MAC optimisation one problem become visible:
hsr_handle_sup_frame() walks over the list of available nodes and merges
two node entries into one if based on the information in the supervision
both MAC addresses belong to one node. The list-walk happens on a RCU
protected list and delete operation happens under a lock.

If the supervision arrives on both slave interfaces at the same time
then this delete operation can occur simultaneously on two CPUs. The
result is the first-CPU deletes the from the list and the second CPUs
BUGs while attempting to dereference a poisoned list-entry. This happens
more likely with the optimisation because a new node for the mac_B entry
is created once a packet has been received and removed (merged) once the
supervision frame has been received.

Avoid removing/ cleaning up a hsr_node twice by adding a `removed' field
which is set to true after the removal and checked before the removal.

Fixes: f266a683a4 ("net/hsr: Better frame dispatch")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Sebastian Andrzej Siewior 2022-11-29 17:48:10 +01:00 committed by Greg Kroah-Hartman
parent de7dbee4bd
commit 6dea95f640
2 changed files with 12 additions and 5 deletions

View File

@ -269,9 +269,12 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
node_real->addr_B_port = port_rcv->type; node_real->addr_B_port = port_rcv->type;
spin_lock_bh(&hsr->list_lock); spin_lock_bh(&hsr->list_lock);
if (!node_curr->removed) {
list_del_rcu(&node_curr->mac_list); list_del_rcu(&node_curr->mac_list);
spin_unlock_bh(&hsr->list_lock); node_curr->removed = true;
kfree_rcu(node_curr, rcu_head); kfree_rcu(node_curr, rcu_head);
}
spin_unlock_bh(&hsr->list_lock);
done: done:
skb_push(skb, sizeof(struct hsrv1_ethhdr_sp)); skb_push(skb, sizeof(struct hsrv1_ethhdr_sp));
@ -436,11 +439,14 @@ void hsr_prune_nodes(struct timer_list *t)
if (time_is_before_jiffies(timestamp + if (time_is_before_jiffies(timestamp +
msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
hsr_nl_nodedown(hsr, node->macaddress_A); hsr_nl_nodedown(hsr, node->macaddress_A);
if (!node->removed) {
list_del_rcu(&node->mac_list); list_del_rcu(&node->mac_list);
node->removed = true;
/* Note that we need to free this entry later: */ /* Note that we need to free this entry later: */
kfree_rcu(node, rcu_head); kfree_rcu(node, rcu_head);
} }
} }
}
spin_unlock_bh(&hsr->list_lock); spin_unlock_bh(&hsr->list_lock);
/* Restart timer */ /* Restart timer */

View File

@ -56,6 +56,7 @@ struct hsr_node {
unsigned long time_in[HSR_PT_PORTS]; unsigned long time_in[HSR_PT_PORTS];
bool time_in_stale[HSR_PT_PORTS]; bool time_in_stale[HSR_PT_PORTS];
u16 seq_out[HSR_PT_PORTS]; u16 seq_out[HSR_PT_PORTS];
bool removed;
struct rcu_head rcu_head; struct rcu_head rcu_head;
}; };