Skip to contentSkip to conversation

IB/core: Fix zero dmac race in neighbor resolution

PATCH Applied Leon Romanovsky 2 participants 2 messages Apr 5 – Apr 9 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IB/core: Fix zero dmac race in neighbor resolution

From: Chen Zhao <[email protected]>

dst_fetch_ha() checks nud_state without holding the neighbor lock, then copies ha under the seqlock. A race in __neigh_update() where nud_state is set to NUD_REACHABLE before ha is written allows dst_fetch_ha() to read a zero MAC address while the seqlock reports no concurrent writer.

netevent_callback amplifies this by waking ALL pending addr_req workers when ANY neighbor becomes NUD_VALID. At scale (N peers resolving ARP concurrently), the hit probability scales as N^2, making it near-certain for large RDMA workloads.

N(A): neigh_update(A) W(A): addr_resolve(A)

 |                                       [sleep]
 | write_lock_bh(&A->lock)               |
 | A->nud_state = NUD_REACHABLE          |
 | // A->ha is still 0                   |
 |                                       [woken by netevent_cb() of
 |                                         another neighbour]
 |                                       | dst_fetch_ha(A)
 |                                       |   A->nud_state & NUD_VALID
 |                                       |   read_seqbegin(&A->ha_lock)
 |                                       |   snapshot = A->ha  /* 0 */
 |                                       |   read_seqretry(&A->ha_lock)
 |                                       |   return snapshot
 | seqlock(&A->ha_lock)
 | A->ha = mac_A     /* too late */
 | sequnlock(&A->ha_lock)
 | write_unlock_bh(&A->lock)

The incorrect/zero mac is read and programmed in the device QP while it was not yet updated. This causes silent packet loss and eventual RETRY_EXC_ERR.

Fix by holding the neighbor read lock across the nud_state check and ha copy in dst_fetch_ha(), ensuring it synchronizes with __neigh_update() which is updating while holding the write lock.

Fixes 92ebb6a0a13a ("IB/cm: Remove now useless rcu_lock in dst_fetch_ha")

---
Strictly speaking the commit in Fixes doesn't look like the one which caused the race, but it is most relevant one to put.

---
 drivers/infiniband/core/addr.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/addr.c +3 -0
index 866746695712a..6526fda8f9c0b 100644
@@ -321,11 +321,14 @@ static int dst_fetch_ha(const struct dst_entry *dst,
 	if (!n)
 		return -ENODATA;
 
+	read_lock_bh(&n->lock);
 	if (!(n->nud_state & NUD_VALID)) {
+		read_unlock_bh(&n->lock);
 		neigh_event_send(n, NULL);
 		ret = -ENODATA;
 	} else {
 		neigh_ha_snapshot(dev_addr->dst_dev_addr, n, dst->dev);
+		read_unlock_bh(&n->lock);
 	}
 
 	neigh_release(n);

---
base-commit: 69db255d5fafb5651013c79e54c1d535fc5015fb
change-id: 20260405-fix-dmac-race-1c57aa966d4d

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>
maintainer Applied
#1 lore raw
Quoted 42 lines · Leon Romanovsky

From: Chen Zhao <[email protected]>

dst_fetch_ha() checks nud_state without holding the neighbor lock, then copies ha under the seqlock. A race in __neigh_update() where nud_state is set to NUD_REACHABLE before ha is written allows dst_fetch_ha() to read a zero MAC address while the seqlock reports no concurrent writer.

netevent_callback amplifies this by waking ALL pending addr_req workers when ANY neighbor becomes NUD_VALID. At scale (N peers resolving ARP concurrently), the hit probability scales as N^2, making it near-certain for large RDMA workloads.

N(A): neigh_update(A) W(A): addr_resolve(A)

 |                                       [sleep]
 | write_lock_bh(&A->lock)               |
 | A->nud_state = NUD_REACHABLE          |
 | // A->ha is still 0                   |
 |                                       [woken by netevent_cb() of
 |                                         another neighbour]
 |                                       | dst_fetch_ha(A)
 |                                       |   A->nud_state & NUD_VALID
 |                                       |   read_seqbegin(&A->ha_lock)
 |                                       |   snapshot = A->ha  /* 0 */
 |                                       |   read_seqretry(&A->ha_lock)
 |                                       |   return snapshot
 | seqlock(&A->ha_lock)
 | A->ha = mac_A     /* too late */
 | sequnlock(&A->ha_lock)
 | write_unlock_bh(&A->lock)

The incorrect/zero mac is read and programmed in the device QP while it was not yet updated. This causes silent packet loss and eventual RETRY_EXC_ERR.

Fix by holding the neighbor read lock across the nud_state check and ha copy in dst_fetch_ha(), ensuring it synchronizes with __neigh_update() which is updating while holding the write lock.

Fixes 92ebb6a0a13a ("IB/cm: Remove now useless rcu_lock in dst_fetch_ha")
Quoted 6 lines

---
Strictly speaking the commit in Fixes doesn't look like the one which caused the race, but it is most relevant one to put.

---
 drivers/infiniband/core/addr.c | 3 +++
 1 file changed, 3 insertions(+)

Applied to for-next

Thanks,
Jason