Skip to contentSkip to conversation

neighbour: fix data-races around n->output

PATCH Applied Eric Dumazet 3 participants 4 messages Sep 21, 2023 – Oct 1, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 neighbour: fix data-races around n->output

n->output field can be read locklessly, while a writer might change the pointer concurrently.

Add missing annotations to prevent load-store tearing.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 include/net/neighbour.h         |  2 +-
 net/bridge/br_netfilter_hooks.c |  2 +-
 net/core/neighbour.c            | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)
include/net/neighbour.h +1 -1
index 6da68886fabbcb33a63ef256242d51a618571c95..07022bb0d44d4b5eef5812cc86e042833cf3a337 100644
@@ -539,7 +539,7 @@ static inline int neigh_output(struct neighbour *n, struct sk_buff *skb,
 	    READ_ONCE(hh->hh_len))
 		return neigh_hh_output(hh, skb);
 
-	return n->output(n, skb);
+	return READ_ONCE(n->output)(n, skb);
 }
 
 static inline struct neighbour *
net/bridge/br_netfilter_hooks.c +1 -1
index 15186247b59af52062907cacec994e736ddbc01b..033034d68f1f057349acdd2f127c427195be6b62 100644
@@ -294,7 +294,7 @@ int br_nf_pre_routing_finish_bridge(struct net *net, struct sock *sk, struct sk_
 			/* tell br_dev_xmit to continue with forwarding */
 			nf_bridge->bridged_dnat = 1;
 			/* FIXME Need to refragment */
-			ret = neigh->output(neigh, skb);
+			ret = READ_ONCE(neigh->output)(neigh, skb);
 		}
 		neigh_release(neigh);
 		return ret;
net/core/neighbour.c +5 -5
index 7212c7e521ef6388f450f3882077e26088bb3644..9c09f091cbffe59043ce4614423d7dce7d4ec42a 100644
@@ -410,7 +410,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev,
 				 */
 				__skb_queue_purge(&n->arp_queue);
 				n->arp_queue_len_bytes = 0;
-				n->output = neigh_blackhole;
+				WRITE_ONCE(n->output, neigh_blackhole);
 				if (n->nud_state & NUD_VALID)
 					n->nud_state = NUD_NOARP;
 				else
@@ -920,7 +920,7 @@ static void neigh_suspect(struct neighbour *neigh)
 {
 	neigh_dbg(2, "neigh %p is suspected\n", neigh);
 
-	neigh->output = neigh->ops->output;
+	WRITE_ONCE(neigh->output, neigh->ops->output);
 }
 
 /* Neighbour state is OK;
@@ -932,7 +932,7 @@ static void neigh_connect(struct neighbour *neigh)
 {
 	neigh_dbg(2, "neigh %p is connected\n", neigh);
 
-	neigh->output = neigh->ops->connected_output;
+	WRITE_ONCE(neigh->output, neigh->ops->connected_output);
 }
 
 static void neigh_periodic_work(struct work_struct *work)
@@ -1449,7 +1449,7 @@ static int __neigh_update(struct neighbour *neigh, const u8 *lladdr,
 				if (n2)
 					n1 = n2;
 			}
-			n1->output(n1, skb);
+			READ_ONCE(n1->output)(n1, skb);
 			if (n2)
 				neigh_release(n2);
 			rcu_read_unlock();
@@ -3155,7 +3155,7 @@ int neigh_xmit(int index, struct net_device *dev,
 			rcu_read_unlock();
 			goto out_kfree_skb;
 		}
-		err = neigh->output(neigh, skb);
+		err = READ_ONCE(neigh->output)(neigh, skb);
 		rcu_read_unlock();
 	}
 	else if (index == NEIGH_LINK_TABLE) {
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Eric Dumazet

n->output field can be read locklessly, while a writer might change the pointer concurrently.

Add missing annotations to prevent load-store tearing.

Quoted 8 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 include/net/neighbour.h         |  2 +-
 net/bridge/br_netfilter_hooks.c |  2 +-
 net/core/neighbour.c            | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

WRITE_ONCE is needed for net/atm/clip.c

#2 lore raw
Quoted 16 lines · David Ahern
Quoted 5 lines · Eric Dumazet

n->output field can be read locklessly, while a writer might change the pointer concurrently.

Add missing annotations to prevent load-store tearing.

Quoted 8 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 include/net/neighbour.h         |  2 +-
 net/bridge/br_netfilter_hooks.c |  2 +-
 net/core/neighbour.c            | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)
Quoted 4 lines

WRITE_ONCE is needed for net/atm/clip.c

Like other constructors (ipv4, ipv6), clip_constructor() is called on a not yet published object,
no particular burier is needed.

Thanks.

#3 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 9 lines · On Thu, 21 Sep 2023 09:27:13 +0000 you wrote:

n->output field can be read locklessly, while a writer might change the pointer concurrently.

Add missing annotations to prevent load-store tearing.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

[...]

Here is the summary with links:
- [net] neighbour: fix data-races around n->output

    https://git.kernel.org/netdev/net/c/5baa0433a15e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html