bridge/vxlan: fix reading neigh ha without synchronization
Subsystems (3)
Nikolay Aleksandrov
maintainerv2 cover bridge/vxlan: fix reading neigh ha without synchronization
Hi,
Neigh ha address must be read using the seqlock to get a stable snapshot. Both the bridge and vxlan read it directly and can see partial updates. I reproduced both issues with running neigh updates and exercising these paths in parallel and saw partial addresses, e.g. updating between neigh A: 02:00:00:00:00:00 neigh B: fe:ff:ff:ff:ff:ff was able to observe 02:00:ff:ff:ff:ff and fe:ff:00:00:00:00 in packets. Noticed this initially in the bridge, then checked vxlan and its arp/neigh_reduce functions have the same bug, route_shortcircuit is doing the right thing already.
v1 link: https://lore.kernel.org/netdev/[email protected]/
v2: - use ETH_ALEN instead of MAX_ADDR_LEN, the bridge devices all use
ETH_ALEN and vxlan allows arp/nd reduce only when not in raw/gpe so it also always uses ETH_ALEN
- align ha to 2 bytes because ether_addr_copy() expects it (Sashiko)
2-byte alignment is not strictly necessary everywhere (e.g. the ARP suppress side can't reach ether_addr_copy) but it doesn't cost us anything and is aligned with the rest of the code.
Cheers,
Nik
Nikolay Aleksandrov (2):
net: bridge: arp/nd proxy: fix reading neigh ha
vxlan: fix reading neigh ha
drivers/net/vxlan/vxlan_core.c | 20 +++++++++++++------- net/bridge/br_arp_nd_proxy.c | 24 ++++++++++++++---------- 2 files changed, 27 insertions(+), 17 deletions(-)
Signature · 1 line
2.47.3
Nikolay Aleksandrov
maintainerPATCH v2 1/2 net: bridge: arp/nd proxy: fix reading neigh ha
Currently neigh ha address is read directly, but that can result in torn/partial reads if the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address.
---
v2: - use ETH_ALEN instead of MAX_ADDR_LEN, the bridge devices all use
ETH_ALEN and vxlan allows arp/nd reduce only when not in raw/gpe so it also always uses ETH_ALEN
- align ha to 2 bytes because ether_addr_copy() expects it (Sashiko)
net/bridge/br_arp_nd_proxy.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
net/bridge/br_arp_nd_proxy.c +14 -10
@@ -195,13 +195,15 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, n =neigh_lookup (&arp_tbl, &tip, vlandev);if (n) {struct net_bridge_fdb_entry *f; +u8 ha[ETH_ALEN ]__aligned(2) ;if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_release (n);return ; } - f =br_fdb_find_rcu (br, n->ha, vid); +neigh_ha_snapshot (ha, n, n->dev); + f =br_fdb_find_rcu (br, ha, vid);if (f) {const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;
@@ -211,10 +213,10 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, br_is_neigh_suppress_enabled(dst, vid)) {if (!vid)br_arp_send (br, p, skb->dev, sip, tip, - sha, n->ha, sha,0 ,0 ); + sha, ha, sha,0 ,0 );else br_arp_send (br, p, skb->dev, sip, tip, - sha, n->ha, sha, + sha, ha, sha, skb->vlan_proto,skb_vlan_tag_get (skb)); replied = true;
@@ -252,7 +254,7 @@ struct nd_msg *br_is_nd_neigh_msg(const struct sk_buff *skb, struct nd_msg *msg) }static void br_nd_send (struct net_bridge *br,struct net_bridge_port *p, -struct sk_buff *request,struct neighbour *n, +struct sk_buff *request,struct neighbour *n,u8 *ha,__be16 vlan_proto,u16 vlan_tci) {struct net_device *dev = request->dev;
@@ -310,7 +312,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,ipv6_eth_mc_map (&in6addr_linklocal_allnodes,eth_hdr (reply)->h_dest); else ether_addr_copy(eth_hdr(reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -340,7 +342,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited = dad ?0 :1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -369,7 +371,7 @@ static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,__vlan_hwaccel_put_tag (reply, vlan_proto, vlan_tci);netdev_dbg (dev,"nd send dev %s dst %pI6 dst_hw %pM src %pI6 src_hw %pM\n" , - dev->name, &pip6->daddr, daddr, &pip6->saddr, n->ha); + dev->name, &pip6->daddr, daddr, &pip6->saddr, ha);if (p) {dev_queue_xmit (reply);
@@ -472,24 +474,26 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, n =neigh_lookup (&nd_tbl, &msg->target, vlandev);if (n) {struct net_bridge_fdb_entry *f; +u8 ha[ETH_ALEN ]__aligned(2) ;if (!(READ_ONCE (n->nud_state) &NUD_VALID )) {neigh_release (n);return ; } - f =br_fdb_find_rcu (br, n->ha, vid); +neigh_ha_snapshot (ha, n, n->dev); + f =br_fdb_find_rcu (br, ha, vid);if (f) {const struct net_bridge_port *dst =READ_ONCE (f->dst);bool replied = false;if (br_is_neigh_suppress_enabled (dst, vid)) {if (vid !=0 ) -br_nd_send (br, p, skb, n, +br_nd_send (br, p, skb, n, ha, skb->vlan_proto,skb_vlan_tag_get (skb));else -br_nd_send (br, p, skb, n,0 ,0 ); +br_nd_send (br, p, skb, n, ha,0 ,0 ); replied = true; }
Signature · 1 line
2.47.3
Re: [PATCH net v2 1/2] net: bridge: arp/nd proxy: fix reading neigh ha
Quoted 7 lines · Nikolay Aleksandrov
Currently neigh ha address is read directly, but that can result in torn/partial reads if the neigh is being updated. Use
neigh_ha_snapshotto take a stable snapshot of the address.Fixes 057658cb33fb ("bridge: suppress arp pkts on BR_NEIGH_SUPPRESS ports")Fixes ed842faeb2bd ("bridge: suppress nd pkts on BR_NEIGH_SUPPRESS ports")Signed-off-by Nikolay Aleksandrov <[email protected]>
net/bridge/br_arp_nd_proxy.c struct nd_msg *br_is_nd_neigh_msg(const struct sk_buff *skb, struct nd_msg *msg) · line 257
Quoted 6 lines
net/bridge/br_arp_nd_proxy.c +1
-1@@ -252,7 +254,7 @@ struct nd_msg *br_is_nd_neigh_msg(const struct sk_buff *skb, struct nd_msg *msg) } static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p, - struct sk_buff *request, struct neighbour *n, + struct sk_buff *request, struct neighbour *n, u8 *ha,
(This looks like it could be const u8 *ha though.)
Quoted 3 lines
net/bridge/br_arp_nd_proxy.c +0
-0__be16 vlan_proto, u16 vlan_tci) {struct net_device *dev = request->dev;
Re: [PATCH net v2 1/2] net: bridge: arp/nd proxy: fix reading neigh ha
In reply to Nikolay AleksandrovQuoted 7 lines · Nikolay Aleksandrov
Currently neigh ha address is read directly, but that can result in torn/partial reads if the neigh is being updated. Use
neigh_ha_snapshotto take a stable snapshot of the address.Fixes 057658cb33fb ("bridge: suppress arp pkts on BR_NEIGH_SUPPRESS ports")Fixes ed842faeb2bd ("bridge: suppress nd pkts on BR_NEIGH_SUPPRESS ports")Signed-off-by Nikolay Aleksandrov <[email protected]>
Nikolay Aleksandrov
maintainerPATCH v2 2/2 vxlan: fix reading neigh ha
In reply to Nikolay AleksandrovCurrently arp/neigh_reduce read neigh ha directly which can lead to partial reads while the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address similar to route_shortcircuit which already does the right thing.
---
v2: - use ETH_ALEN instead of MAX_ADDR_LEN, the bridge devices all use
ETH_ALEN and vxlan allows arp/nd reduce only when not in raw/gpe so it also always uses ETH_ALEN
- align ha to 2 bytes because ether_addr_copy() expects it (Sashiko)
drivers/net/vxlan/vxlan_core.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/vxlan/vxlan_core.c +13 -7
@@ -1881,6 +1881,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -1889,8 +1890,10 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } +neigh_ha_snapshot (ha, n, n->dev); +rcu_read_lock (); - f =vxlan_find_mac_tx (vxlan, n->ha, vni); + f =vxlan_find_mac_tx (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -1902,7 +1905,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)rcu_read_unlock (); reply =arp_create (ARPOP_REPLY ,ETH_P_ARP , sip, dev, tip, sha, - n->ha, sha); + ha, sha);neigh_release (n);
@@ -1935,7 +1938,8 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)#if IS_ENABLED (CONFIG_IPV6 )static struct sk_buff *vxlan_na_create (struct sk_buff *request, -struct neighbour *n,bool isrouter) +struct neighbour *n,u8 *ha, +bool isrouter) {struct net_device *dev = request->dev;struct sk_buff *reply;
@@ -1981,7 +1985,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request,/* Ethernet header */ ether_addr_copy (eth_hdr (reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -2010,7 +2014,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited =1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -2051,6 +2055,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -2059,7 +2064,8 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - f =vxlan_find_mac_tx (vxlan, n->ha, vni); +neigh_ha_snapshot (ha, n, n->dev); + f =vxlan_find_mac_tx (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -2068,7 +2074,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - reply =vxlan_na_create (skb, n, + reply =vxlan_na_create (skb, n, ha, !!(f ? f->flags &NTF_ROUTER :0 ));neigh_release (n);
Signature · 1 line
2.47.3
Re: [PATCH net v2 2/2] vxlan: fix reading neigh ha
Quoted 8 lines · Nikolay Aleksandrov
Currently arp/neigh_reduce read neigh ha directly which can lead to partial reads while the neigh is being updated. Use
neigh_ha_snapshotto take a stable snapshot of the address similar toroute_shortcircuitwhich already does the right thing.Fixes e4f67addf158 ("add DOVE extensions for VXLAN")Fixes f564f45c4518 ("vxlan: add ipv6 proxy support")Signed-off-by Nikolay Aleksandrov <[email protected]>
drivers/net/vxlan/vxlan_core.c static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) · line 1941
Quoted 6 lines
drivers/net/vxlan/vxlan_core.c +1
-1@@ -1935,7 +1938,8 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)#if IS_ENABLED (CONFIG_IPV6 ) static struct sk_buff *vxlan_na_create(struct sk_buff *request, -struct neighbour *n,bool isrouter) + struct neighbour *n, u8 *ha,
(Likewise, I think this could be const u8 *ha.)
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +1
-0+ bool isrouter) {struct net_device *dev = request->dev;struct sk_buff *reply;
Re: [PATCH net v2 2/2] vxlan: fix reading neigh ha
In reply to Nikolay AleksandrovQuoted 8 lines · Nikolay Aleksandrov
Currently arp/neigh_reduce read neigh ha directly which can lead to partial reads while the neigh is being updated. Use
neigh_ha_snapshotto take a stable snapshot of the address similar toroute_shortcircuitwhich already does the right thing.Fixes e4f67addf158 ("add DOVE extensions for VXLAN")Fixes f564f45c4518 ("vxlan: add ipv6 proxy support")Signed-off-by Nikolay Aleksandrov <[email protected]>
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Tue, 18 Aug 2026 18:07:54 +0300 you wrote:
Hi,
Neigh ha address must be read using the seqlock to get a stable snapshot. Both the bridge and vxlan read it directly and can see partial updates. I reproduced both issues with running neigh updates and exercising these paths in parallel and saw partial addresses, e.g. updating between neigh A: 02:00:00:00:00:00 neigh B: fe:ff:ff:ff:ff:ff was able to observe 02:00:ff:ff:ff:ff and fe:ff:00:00:00:00 in packets. Noticed this initially in the bridge, then checked vxlan and its arp/neigh_reduce functions have the same bug,route_shortcircuitis doing the right thing already.[...]
Here is the summary with links:
- [net,v2,1/2] net: bridge: arp/nd proxy: fix reading neigh ha
https://git.kernel.org/netdev/net/c/57549ab90791 - [net,v2,2/2] vxlan: fix reading neigh ha https://git.kernel.org/netdev/net/c/b824059a673b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html