vxlan: fixes for skb header pulling, cloning, and concurrency in TX path
Subsystems (3)
cover vxlan: fixes for skb header pulling, cloning, and concurrency in TX path
While working on RTNL-less fill_info for vxlan, Sashiko found annoying pre-existing issues, adding noise to an already complex work.
This series addresses some of them in VXLAN transmit path, primarily within route_shortcircuit(), header validation, and neighbour lookup.
Patch 1 fixes a potential use-after-free in vxlan_xmit() caused by caching the Ethernet header pointer ('eth') before calling route_shortcircuit(), which can reallocate skb->head via pskb_may_pull().
Patch 2 calls skb_cow_head() in route_shortcircuit() before modifying the Ethernet header in-place, preventing packet header corruption when the skb is cloned (e.g., by packet sockets, tcpdump, or dev_queue_xmit).
Patch 3 replaces direct reads of n->ha in route_shortcircuit() with neigh_ha_snapshot() to safely snapshot the neighbour hardware address under seqlock protection, avoiding potential torn reads during asynchronous updates.
Patch 4 changes route_shortcircuit() to use pskb_network_may_pull() instead of pskb_may_pull(). Since skb->data points to the MAC header on transmit (skb_network_offset(skb) == ETH_HLEN), pskb_may_pull() was only checking 6 bytes into the IP header, leaving the remainder un-pulled in non-linear frags.
Patch 5 applies pskb_network_may_pull() to the remaining transmit-path header pull checks in arp_reduce(), ND solicitation proxy checks, and MDB entry lookup, where skb->data similarly points to the Ethernet header.
Eric Dumazet (5):
vxlan: re-fetch eth header after route_shortcircuit()
vxlan: unclone skb head before modifying eth header in
route_shortcircuit()
vxlan: use neigh_ha_snapshot() in route_shortcircuit()
vxlan: use pskb_network_may_pull() in route_shortcircuit()
vxlan: use pskb_network_may_pull() for transmit path header pulls
drivers/net/vxlan/vxlan_core.c | 21 ++++++++++++++------- drivers/net/vxlan/vxlan_mdb.c | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-)
Signature · 1 line
2.55.0.229.g6434b31f56-goog
PATCH 1/5 vxlan: re-fetch eth header after route_shortcircuit()
Before route_shortcircuit(), the eth header pointer is cached from eth_hdr(skb).
Inside route_shortcircuit(), pskb_may_pull() can be called, which may reallocate skb->head.
In this case, returning to vxlan_xmit() leaves the cached eth pointer pointing to freed memory, leading to a use-after-free when dereferencing eth->h_dest.
Fix this by updating eth = eth_hdr(skb) after calling route_shortcircuit().
--- drivers/net/vxlan/vxlan_core.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/vxlan/vxlan_core.c +1 -0
@@ -2796,6 +2796,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) (ntohs(eth->h_proto) == ETH_P_IP || ntohs(eth->h_proto) == ETH_P_IPV6)) { did_rsc =route_shortcircuit (dev, skb); + eth =eth_hdr (skb);if (did_rsc) f =vxlan_find_mac_tx (vxlan, eth->h_dest, vni); }
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Re: [PATCH net 1/5] vxlan: re-fetch eth header after route_shortcircuit()
Quoted 22 lines · Eric Dumazet
Before
route_shortcircuit(), the eth header pointer is cached frometh_hdr(skb).Inside
route_shortcircuit(),pskb_may_pull()can be called, which may reallocateskb->head.In this case, returning to
vxlan_xmit()leaves the cached eth pointer pointing to freed memory, leading to a use-after-free when dereferencingeth->h_dest.Fix this by updating eth =
eth_hdr(skb)after callingroute_shortcircuit().Fixes ae8840825605 ("VXLAN: Allow L2 redirection with L3 switching")Signed-off-by Eric Dumazet <[email protected]>--- drivers/net/vxlan/vxlan_core.c | 1 + 1 file changed, 1 insertion(+)drivers/net/vxlan/vxlan_core.c +0
-0
drivers/net/vxlan/vxlan_core.c static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) · line 2802
Quoted 7 lines
drivers/net/vxlan/vxlan_core.c +1
-0@@ -2796,6 +2796,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) (ntohs(eth->h_proto) == ETH_P_IP || ntohs(eth->h_proto) == ETH_P_IPV6)) { did_rsc =route_shortcircuit (dev, skb); + eth =eth_hdr (skb);if (did_rsc) f =vxlan_find_mac_tx (vxlan, eth->h_dest, vni); }
PATCH 2/5 vxlan: unclone skb head before modifying eth header in route_shortcircuit()
In reply to Eric DumazetWhen route_shortcircuit() performs L3 short-circuit routing, it modifies the Ethernet header of the skb in-place:
memcpy(eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, dev->addr_len);
memcpy(eth_hdr(skb)->h_dest, n->ha, dev->addr_len);If the incoming skb is cloned (for example by packet sockets, tcpdump, or dev_queue_xmit), modifying the Ethernet header without uncloning can corrupt the packet header for other readers holding a reference to the cloned skb.
Ensure the skb header is writable and unshared by calling skb_cow_head(skb, 0) prior to updating the Ethernet header. If skb_cow_head() fails, abort short-circuiting and return false to allow standard packet processing fallback.
--- drivers/net/vxlan/vxlan_core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/vxlan/vxlan_core.c +4 -0
@@ -2163,6 +2163,10 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) diff = !ether_addr_equal (eth_hdr (skb)->h_dest, n->ha);if (diff) { +if (skb_cow_head (skb,0 )) { +neigh_release (n); +return false; + }memcpy (eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest, dev->addr_len);memcpy (eth_hdr (skb)->h_dest, n->ha, dev->addr_len);
Signature · 1 line
2.55.0.229.g6434b31f56-goog
PATCH 3/5 vxlan: use neigh_ha_snapshot() in route_shortcircuit()
In reply to Eric DumazetThe neighbour hardware address n->ha can be updated asynchronously by the neighbour subsystem, protected by n->ha_lock seqlock. Reading n->ha without holding the seqlock loop can lead to torn reads or reading a partially updated MAC address.
Use neigh_ha_snapshot() in route_shortcircuit() to safely copy n->ha under read_seqbegin()/read_seqretry() lock protection before using it.
Note that arp_reduce() and neigh_reduce() seem to have the same issue left for future patches.
--- drivers/net/vxlan/vxlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/vxlan/vxlan_core.c +4 -2
@@ -2159,9 +2159,11 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) }if (n) { +u8 haddr[ETH_ALEN ];bool diff; - diff = !ether_addr_equal (eth_hdr (skb)->h_dest, n->ha); +neigh_ha_snapshot (haddr, n, dev); + diff = !ether_addr_equal_unaligned (eth_hdr (skb)->h_dest, haddr);if (diff) {if (skb_cow_head (skb,0 )) {neigh_release (n);
@@ -2169,7 +2171,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) }memcpy (eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest, dev->addr_len); -memcpy (eth_hdr (skb)->h_dest, n->ha, dev->addr_len); +memcpy (eth_hdr (skb)->h_dest, haddr, dev->addr_len); }neigh_release (n);return diff;
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Re: [PATCH net 3/5] vxlan: use neigh_ha_snapshot() in route_shortcircuit()
Quoted 36 lines · Eric Dumazet
The neighbour hardware address
n->hacan be updated asynchronously by the neighbour subsystem, protected byn->ha_lockseqlock. Readingn->hawithout holding the seqlock loop can lead to torn reads or reading a partially updated MAC address.Use
neigh_ha_snapshot()inroute_shortcircuit()to safely copyn->haunder read_seqbegin()/read_seqretry() lock protection before using it.Note that
arp_reduce()andneigh_reduce()seem to have the same issue left for future patches.Fixes e4f67addf158 ("add DOVE extensions for VXLAN")Signed-off-by Eric Dumazet <[email protected]>--- drivers/net/vxlan/vxlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/net/vxlan/vxlan_core.c +3
-1@@ -2159,9 +2159,11 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) }if (n) { +u8 haddr[ETH_ALEN ];bool diff; - diff = !ether_addr_equal (eth_hdr (skb)->h_dest, n->ha); +neigh_ha_snapshot (haddr, n, dev); + diff = !ether_addr_equal_unaligned (eth_hdr (skb)->h_dest, haddr);if (diff) {if (skb_cow_head (skb,0 )) {neigh_release (n);
drivers/net/vxlan/vxlan_core.c static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · line 2177
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c +1
-1@@ -2169,7 +2171,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) }memcpy (eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest, dev->addr_len); -memcpy (eth_hdr (skb)->h_dest, n->ha, dev->addr_len); +memcpy (eth_hdr (skb)->h_dest, haddr, dev->addr_len); }neigh_release (n);return diff;
PATCH 4/5 vxlan: use pskb_network_may_pull() in route_shortcircuit()
In reply to Eric Dumazetroute_shortcircuit() currently calls pskb_may_pull(skb, sizeof(struct iphdr)) (or ipv6hdr), which checks if bytes are available starting from skb->data.
However, in vxlan_xmit(), skb->data points to the MAC header, so skb_network_offset(skb) is ETH_HLEN (14 bytes). Using pskb_may_pull(skb, 20) only checks 20 bytes from skb->data (which is 14 bytes MAC header + 6 bytes of IP header), leaving the rest of the IP header potentially un-pulled in non-linear frags. Subsequent dereferences of ip_hdr(skb)->daddr can read beyond the pulled linear buffer length.
Fix this by using pskb_network_may_pull(), which adds skb_network_offset(skb) to the length check to ensure the full network header is present in the linear buffer.
--- drivers/net/vxlan/vxlan_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/vxlan/vxlan_core.c +2 -2
@@ -2111,7 +2111,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) {struct iphdr *pip; -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct iphdr )))return false; pip =ip_hdr (skb); n =neigh_lookup (&arp_tbl, &pip->daddr, dev);
@@ -2137,7 +2137,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)*/ if (!ipv6_mod_enabled ())return false; -if (!pskb_may_pull (skb,sizeof (struct ipv6hdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )))return false; pip6 =ipv6_hdr (skb); n =neigh_lookup (&nd_tbl, &pip6->daddr, dev);
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Re: [PATCH net 4/5] vxlan: use pskb_network_may_pull() in route_shortcircuit()
Quoted 34 lines · Eric Dumazet
route_shortcircuit()currently callspskb_may_pull(skb, sizeof(struct iphdr))(or ipv6hdr), which checks if bytes are available starting fromskb->data.However, in
vxlan_xmit(),skb->datapoints to the MAC header, soskb_network_offset(skb)isETH_HLEN(14 bytes). Usingpskb_may_pull(skb, 20)only checks 20 bytes fromskb->data(which is 14 bytes MAC header + 6 bytes of IP header), leaving the rest of the IP header potentially un-pulled in non-linear frags. Subsequent dereferences of ip_hdr(skb)->daddr can read beyond the pulled linear buffer length.Fix this by using
pskb_network_may_pull(), which addsskb_network_offset(skb)to the length check to ensure the full network header is present in the linear buffer.Fixes e4f67addf158 ("add DOVE extensions for VXLAN")Signed-off-by Eric Dumazet <[email protected]>--- drivers/net/vxlan/vxlan_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/vxlan/vxlan_core.c +1
-1@@ -2111,7 +2111,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) {struct iphdr *pip; -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct iphdr )))return false; pip =ip_hdr (skb); n =neigh_lookup (&arp_tbl, &pip->daddr, dev);
drivers/net/vxlan/vxlan_core.c static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · line 2143
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c +1
-1@@ -2137,7 +2137,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)*/ if (!ipv6_mod_enabled ())return false; -if (!pskb_may_pull (skb,sizeof (struct ipv6hdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )))return false; pip6 =ipv6_hdr (skb); n =neigh_lookup (&nd_tbl, &pip6->daddr, dev);
PATCH 5/5 vxlan: use pskb_network_may_pull() for transmit path header pulls
In reply to Eric DumazetIn vxlan_xmit(), arp_reduce(), and vxlan_mdb_entry_skb_get(), pskb_may_pull() was being called to verify the availability of network layer headers (ARP, IPv6/ND, IP/IPv6 MDB keys).
However, during transmit skb->data points to the MAC header, so skb_network_offset(skb) is ETH_HLEN (14 bytes). Using pskb_may_pull(skb, len) only checks len bytes from skb->data rather than skb_network_offset(skb) + len, which can leave part of the network header in non-linear frags.
Replace these remaining pskb_may_pull() calls with pskb_network_may_pull() to properly account for the MAC header offset.
--- drivers/net/vxlan/vxlan_core.c | 6 +++--- drivers/net/vxlan/vxlan_mdb.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/vxlan/vxlan_core.c +3 -3
@@ -1850,7 +1850,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (dev->flags &IFF_NOARP ) goto out; -if (!pskb_may_pull (skb,arp_hdr_len (dev))) { +if (!pskb_network_may_pull (skb,arp_hdr_len (dev))) {dev_dstats_tx_dropped (dev);vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 );
@@ -2763,8 +2763,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)return arp_reduce (dev, skb, vni); #if IS_ENABLED(CONFIG_IPV6) else if (ntohs(eth->h_proto) == ETH_P_IPV6 && - pskb_may_pull(skb, sizeof(struct ipv6hdr) + - sizeof(struct nd_msg)) && + pskb_network_may_pull(skb, sizeof(struct ipv6hdr) + + sizeof(struct nd_msg)) && ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {struct nd_msg *m = (struct nd_msg *)(ipv6_hdr (skb) +1 );
drivers/net/vxlan/vxlan_mdb.c +2 -2
@@ -1631,7 +1631,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,switch (skb->protocol) {case htons (ETH_P_IP ): -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct iphdr )))return NULL ; group.dst.sa.sa_family =AF_INET ; group.dst.sin.sin_addr.s_addr =ip_hdr (skb)->daddr;
@@ -1640,7 +1640,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,break ;#if IS_ENABLED (CONFIG_IPV6 )case htons (ETH_P_IPV6 ): -if (!pskb_may_pull (skb,sizeof (struct ipv6hdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )))return NULL ; group.dst.sa.sa_family =AF_INET6 ; group.dst.sin6.sin6_addr =ipv6_hdr (skb)->daddr;
Signature · 1 line
2.55.0.229.g6434b31f56-goog
Re: [PATCH net 5/5] vxlan: use pskb_network_may_pull() for transmit path header pulls
Quoted 60 lines · Eric Dumazet
In
vxlan_xmit(),arp_reduce(), andvxlan_mdb_entry_skb_get(),pskb_may_pull()was being called to verify the availability of network layer headers (ARP, IPv6/ND, IP/IPv6 MDB keys).However, during transmit
skb->datapoints to the MAC header, soskb_network_offset(skb)isETH_HLEN(14 bytes). Usingpskb_may_pull(skb, len)only checks len bytes fromskb->datarather thanskb_network_offset(skb)+ len, which can leave part of the network header in non-linear frags.Replace these remaining
pskb_may_pull()calls withpskb_network_may_pull()to properly account for the MAC header offset.Fixes 465016142711 ("vxlan: Add ARP reduction support")Fixes 9e061a50a116 ("vxlan: Add IPv6 Neighbor Discovery reduction support")Fixes 4e94f09d84bf ("vxlan: add MDB support")Signed-off-by Eric Dumazet <[email protected]>--- drivers/net/vxlan/vxlan_core.c | 6 +++--- drivers/net/vxlan/vxlan_mdb.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/net/vxlan/vxlan_core.c +3
-3@@ -1850,7 +1850,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (dev->flags &IFF_NOARP ) goto out; -if (!pskb_may_pull (skb,arp_hdr_len (dev))) { +if (!pskb_network_may_pull (skb,arp_hdr_len (dev))) {dev_dstats_tx_dropped (dev);vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 );@@ -2763,8 +2763,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)return arp_reduce (dev, skb, vni); #if IS_ENABLED(CONFIG_IPV6) else if (ntohs(eth->h_proto) == ETH_P_IPV6 && - pskb_may_pull(skb, sizeof(struct ipv6hdr) + - sizeof(struct nd_msg)) && + pskb_network_may_pull(skb, sizeof(struct ipv6hdr) + + sizeof(struct nd_msg)) && ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {struct nd_msg *m = (struct nd_msg *)(ipv6_hdr (skb) +1 );drivers/net/vxlan/vxlan_mdb.c +1
-1@@ -1631,7 +1631,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,switch (skb->protocol) {case htons (ETH_P_IP ): -if (!pskb_may_pull (skb,sizeof (struct iphdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct iphdr )))return NULL ; group.dst.sa.sa_family =AF_INET ; group.dst.sin.sin_addr.s_addr =ip_hdr (skb)->daddr;
drivers/net/vxlan/vxlan_mdb.c struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, · line 1646
Quoted 8 lines
drivers/net/vxlan/vxlan_mdb.c +1
-1@@ -1640,7 +1640,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,break ;#if IS_ENABLED (CONFIG_IPV6 )case htons (ETH_P_IPV6 ): -if (!pskb_may_pull (skb,sizeof (struct ipv6hdr ))) +if (!pskb_network_may_pull (skb,sizeof (struct ipv6hdr )))return NULL ; group.dst.sa.sa_family =AF_INET6 ; group.dst.sin6.sin6_addr =ipv6_hdr (skb)->daddr;
Re: [PATCH net 5/5] vxlan: use pskb_network_may_pull() for transmit path header pulls
In reply to Eric DumazetQuoted 9 lines · Eric Dumazet
In
vxlan_xmit(),arp_reduce(), andvxlan_mdb_entry_skb_get(),pskb_may_pull()was being called to verify the availability of network layer headers (ARP, IPv6/ND, IP/IPv6 MDB keys).However, during transmit
skb->datapoints to the MAC header, soskb_network_offset(skb)isETH_HLEN(14 bytes). Usingpskb_may_pull(skb, len)only checks len bytes fromskb->datarather thanskb_network_offset(skb)+ len, which can leave part of the network header in non-linear frags.
Quoted 6 lines
Replace these remaining
pskb_may_pull()calls withpskb_network_may_pull()to properly account for the MAC header offset.Fixes 465016142711 ("vxlan: Add ARP reduction support")Fixes 9e061a50a116 ("vxlan: Add IPv6 Neighbor Discovery reduction support")Fixes 4e94f09d84bf ("vxlan: add MDB support")
I think you meant:
Quoted 2 lines
Signed-off-by Eric Dumazet <[email protected]>
Thanks!
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 Thu, 23 Jul 2026 14:42:44 +0000 you wrote:
While working on RTNL-less
fill_infofor vxlan, Sashiko found annoying pre-existing issues, adding noise to an already complex work.This series addresses some of them in VXLAN transmit path, primarily within
route_shortcircuit(), header validation, and neighbour lookup.Patch 1 fixes a potential use-after-free in
vxlan_xmit()caused by caching the Ethernet header pointer ('eth') before callingroute_shortcircuit(), which can reallocateskb->headviapskb_may_pull().[...]
Here is the summary with links:
- [net,1/5] vxlan: re-fetch eth header after route_shortcircuit()
https://git.kernel.org/netdev/net/c/1395a676ec15 - [net,2/5] vxlan: unclone skb head before modifying eth header in route_shortcircuit() https://git.kernel.org/netdev/net/c/760d36e737f2 - [net,3/5] vxlan: use neigh_ha_snapshot() in route_shortcircuit() https://git.kernel.org/netdev/net/c/8eca411347e1 - [net,4/5] vxlan: use pskb_network_may_pull() in route_shortcircuit() https://git.kernel.org/netdev/net/c/26bb2dd0a883 - [net,5/5] vxlan: use pskb_network_may_pull() for transmit path header pulls https://git.kernel.org/netdev/net/c/b9553558b48d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html