Skip to content

Commit f5df299

Browse files
MocLGkuba-moo
authored andcommitted
net: hsr: serialize seq_blocks merge across nodes
During node merging, hsr_handle_sup_frame() walks node_curr->seq_blocks to update node_real without holding node_curr->seq_out_lock. This allows concurrent mutations from duplicate registration paths, risking inconsistent state or XArray/bitmap corruption. Fix this by locking both nodes' seq_out_lock during the merge. To prevent ABBA deadlocks, locks are acquired in order of memory address. Reviewed-by: Felix Maurer <[email protected]> Fixes: 415e636 ("hsr: Implement more robust duplicate discard for PRP") Signed-off-by: Luka Gejak <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b18c833 commit f5df299

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

net/hsr/hsr_framereg.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,40 @@ static void hsr_free_node_rcu(struct rcu_head *rn)
123123
hsr_free_node(node);
124124
}
125125

126+
static void hsr_lock_seq_out_pair(struct hsr_node *node_a,
127+
struct hsr_node *node_b)
128+
{
129+
if (node_a == node_b) {
130+
spin_lock_bh(&node_a->seq_out_lock);
131+
return;
132+
}
133+
134+
if (node_a < node_b) {
135+
spin_lock_bh(&node_a->seq_out_lock);
136+
spin_lock_nested(&node_b->seq_out_lock, SINGLE_DEPTH_NESTING);
137+
} else {
138+
spin_lock_bh(&node_b->seq_out_lock);
139+
spin_lock_nested(&node_a->seq_out_lock, SINGLE_DEPTH_NESTING);
140+
}
141+
}
142+
143+
static void hsr_unlock_seq_out_pair(struct hsr_node *node_a,
144+
struct hsr_node *node_b)
145+
{
146+
if (node_a == node_b) {
147+
spin_unlock_bh(&node_a->seq_out_lock);
148+
return;
149+
}
150+
151+
if (node_a < node_b) {
152+
spin_unlock(&node_b->seq_out_lock);
153+
spin_unlock_bh(&node_a->seq_out_lock);
154+
} else {
155+
spin_unlock(&node_a->seq_out_lock);
156+
spin_unlock_bh(&node_b->seq_out_lock);
157+
}
158+
}
159+
126160
void hsr_del_nodes(struct list_head *node_db)
127161
{
128162
struct hsr_node *node;
@@ -432,7 +466,7 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
432466
}
433467

434468
ether_addr_copy(node_real->macaddress_B, ethhdr->h_source);
435-
spin_lock_bh(&node_real->seq_out_lock);
469+
hsr_lock_seq_out_pair(node_real, node_curr);
436470
for (i = 0; i < HSR_PT_PORTS; i++) {
437471
if (!node_curr->time_in_stale[i] &&
438472
time_after(node_curr->time_in[i], node_real->time_in[i])) {
@@ -455,7 +489,7 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
455489
src_blk->seq_nrs[i], HSR_SEQ_BLOCK_SIZE);
456490
}
457491
}
458-
spin_unlock_bh(&node_real->seq_out_lock);
492+
hsr_unlock_seq_out_pair(node_real, node_curr);
459493
node_real->addr_B_port = port_rcv->type;
460494

461495
spin_lock_bh(&hsr->list_lock);

0 commit comments

Comments
 (0)