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. ====================
Unified · Split
| @@ -1850,7 +1850,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) · 1849 unmodified lines | ||
| 1850 | 1850 | if (dev->flags & IFF_NOARP) |
| 1851 | 1851 | goto out; |
| 1852 | 1852 | |
| 1853 | − if (!pskb_may_pull(skb, arp_hdr_len(dev))) { | |
| 1853 | + if (!pskb_network_may_pull(skb, arp_hdr_len(dev))) { | |
| 1854 | 1854 | dev_dstats_tx_dropped(dev); |
| 1855 | 1855 | vxlan_vnifilter_count(vxlan, vni, NULL, |
| 1856 | 1856 | 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 | ||
| 2111 | 2111 | { |
| 2112 | 2112 | struct iphdr *pip; |
| 2113 | 2113 | |
| 2114 | − if (!pskb_may_pull(skb, sizeof(struct iphdr))) | |
| 2114 | + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) | |
| 2115 | 2115 | return false; |
| 2116 | 2116 | pip = ip_hdr(skb); |
| 2117 | 2117 | 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 | ||
| 2137 | 2137 | */ |
| 2138 | 2138 | if (!ipv6_mod_enabled()) |
| 2139 | 2139 | return false; |
| 2140 | − if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | |
| 2140 | + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) | |
| 2141 | 2141 | return false; |
| 2142 | 2142 | pip6 = ipv6_hdr(skb); |
| 2143 | 2143 | 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 | ||
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | if (n) { |
| 2162 | + u8 haddr[ETH_ALEN]; | |
| 2162 | 2163 | bool diff; |
| 2163 | 2164 | |
| 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); | |
| 2165 | 2167 | if (diff) { |
| 2168 | + if (skb_cow_head(skb, 0)) { | |
| 2169 | + neigh_release(n); | |
| 2170 | + return false; | |
| 2171 | + } | |
| 2166 | 2172 | memcpy(eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, |
| 2167 | 2173 | 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); | |
| 2169 | 2175 | } |
| 2170 | 2176 | neigh_release(n); |
| 2171 | 2177 | return diff; |
| @@ -2757,8 +2763,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) · 585 unmodified lines | ||
| 2757 | 2763 | return arp_reduce(dev, skb, vni); |
| 2758 | 2764 | #if IS_ENABLED(CONFIG_IPV6) |
| 2759 | 2765 | 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)) && | |
| 2762 | 2768 | ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) { |
| 2763 | 2769 | struct nd_msg *m = (struct nd_msg *)(ipv6_hdr(skb) + 1); |
| 2764 | 2770 | |
| @@ -2796,6 +2802,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) · 31 unmodified lines | ||
| 2796 | 2802 | (ntohs(eth->h_proto) == ETH_P_IP || |
| 2797 | 2803 | ntohs(eth->h_proto) == ETH_P_IPV6)) { |
| 2798 | 2804 | did_rsc = route_shortcircuit(dev, skb); |
| 2805 | + eth = eth_hdr(skb); | |
| 2799 | 2806 | if (did_rsc) |
| 2800 | 2807 | f = vxlan_find_mac_tx(vxlan, eth->h_dest, vni); |
| 2801 | 2808 | } |
| @@ -1631,7 +1631,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, · 1630 unmodified lines | ||
| 1631 | 1631 | |
| 1632 | 1632 | switch (skb->protocol) { |
| 1633 | 1633 | case htons(ETH_P_IP): |
| 1634 | − if (!pskb_may_pull(skb, sizeof(struct iphdr))) | |
| 1634 | + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) | |
| 1635 | 1635 | return NULL; |
| 1636 | 1636 | group.dst.sa.sa_family = AF_INET; |
| 1637 | 1637 | 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 | ||
| 1640 | 1640 | break; |
| 1641 | 1641 | #if IS_ENABLED(CONFIG_IPV6) |
| 1642 | 1642 | case htons(ETH_P_IPV6): |
| 1643 | − if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | |
| 1643 | + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) | |
| 1644 | 1644 | return NULL; |
| 1645 | 1645 | group.dst.sa.sa_family = AF_INET6; |
| 1646 | 1646 | group.dst.sin6.sin6_addr = ipv6_hdr(skb)->daddr; |