History

Merge branch 'vxlan-fixes-for-skb-header-pulling-cloning-and-concurrency-in-tx-path'

Eric Dumazet says: ==================== 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. ====================

Jakub Kicinski committed 3 months ago

Commit 9c889292 parents dbc3791 b9553552 files · +16 −9Browse files

Unified · Split

2 files
  1. drivers/net/vxlan/vxlan_core.c +14 −7
  2. drivers/net/vxlan/vxlan_mdb.c +2 −2
drivers/net/vxlan/vxlan_core.c+14−7
@@ -1850,7 +1850,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) · 1849 unmodified lines
18501850 if (dev->flags & IFF_NOARP)
18511851 goto out;
18521852
1853− if (!pskb_may_pull(skb, arp_hdr_len(dev))) {
1853+ if (!pskb_network_may_pull(skb, arp_hdr_len(dev))) {
18541854 dev_dstats_tx_dropped(dev);
18551855 vxlan_vnifilter_count(vxlan, vni, NULL,
18561856 VXLAN_VNI_STATS_TX_DROPS, 0);
@@ -2111,7 +2111,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · 254 unmodified lines
21112111 {
21122112 struct iphdr *pip;
21132113
2114− if (!pskb_may_pull(skb, sizeof(struct iphdr)))
2114+ if (!pskb_network_may_pull(skb, sizeof(struct iphdr)))
21152115 return false;
21162116 pip = ip_hdr(skb);
21172117 n = neigh_lookup(&arp_tbl, &pip->daddr, dev);
@@ -2137,7 +2137,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · 19 unmodified lines
21372137 */
21382138 if (!ipv6_mod_enabled())
21392139 return false;
2140− if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
2140+ if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr)))
21412141 return false;
21422142 pip6 = ipv6_hdr(skb);
21432143 n = neigh_lookup(&nd_tbl, &pip6->daddr, dev);
@@ -2159,13 +2159,19 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · 15 unmodified lines
21592159 }
21602160
21612161 if (n) {
2162+ u8 haddr[ETH_ALEN];
21622163 bool diff;
21632164
2164− diff = !ether_addr_equal(eth_hdr(skb)->h_dest, n->ha);
2165+ neigh_ha_snapshot(haddr, n, dev);
2166+ diff = !ether_addr_equal_unaligned(eth_hdr(skb)->h_dest, haddr);
21652167 if (diff) {
2168+ if (skb_cow_head(skb, 0)) {
2169+ neigh_release(n);
2170+ return false;
2171+ }
21662172 memcpy(eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
21672173 dev->addr_len);
2168− memcpy(eth_hdr(skb)->h_dest, n->ha, dev->addr_len);
2174+ memcpy(eth_hdr(skb)->h_dest, haddr, dev->addr_len);
21692175 }
21702176 neigh_release(n);
21712177 return diff;
@@ -2757,8 +2763,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) · 585 unmodified lines
27572763 return arp_reduce(dev, skb, vni);
27582764 #if IS_ENABLED(CONFIG_IPV6)
27592765 else if (ntohs(eth->h_proto) == ETH_P_IPV6 &&
2760− pskb_may_pull(skb, sizeof(struct ipv6hdr) +
2761− sizeof(struct nd_msg)) &&
2766+ pskb_network_may_pull(skb, sizeof(struct ipv6hdr) +
2767+ sizeof(struct nd_msg)) &&
27622768 ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {
27632769 struct nd_msg *m = (struct nd_msg *)(ipv6_hdr(skb) + 1);
27642770
@@ -2796,6 +2802,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) · 31 unmodified lines
27962802 (ntohs(eth->h_proto) == ETH_P_IP ||
27972803 ntohs(eth->h_proto) == ETH_P_IPV6)) {
27982804 did_rsc = route_shortcircuit(dev, skb);
2805+ eth = eth_hdr(skb);
27992806 if (did_rsc)
28002807 f = vxlan_find_mac_tx(vxlan, eth->h_dest, vni);
28012808 }
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, · 1630 unmodified lines
16311631
16321632 switch (skb->protocol) {
16331633 case htons(ETH_P_IP):
1634− if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1634+ if (!pskb_network_may_pull(skb, sizeof(struct iphdr)))
16351635 return NULL;
16361636 group.dst.sa.sa_family = AF_INET;
16371637 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, · 2 unmodified lines
16401640 break;
16411641 #if IS_ENABLED(CONFIG_IPV6)
16421642 case htons(ETH_P_IPV6):
1643− if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
1643+ if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr)))
16441644 return NULL;
16451645 group.dst.sa.sa_family = AF_INET6;
16461646 group.dst.sin6.sin6_addr = ipv6_hdr(skb)->daddr;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t