A frag_list skb can reach veth with data_len set but nr_frags zero. veth_convert_skb_to_xdp_buff() only converts skbs that are shared, locked, have frags[], or do not have enough headroom. It later uses skb_is_nonlinear() to decide whether to set XDP_FLAGS_HAS_FRAGS and xdp_frags_size. That exposes frag_list data to XDP as if it were stored in frags[], but frags[] is empty. AF_XDP copy mode can then trust the bogus XDP fragment metadata, walk an empty fragment entry, and crash in memcpy() from __xsk_rcv(). Route non-linear skbs through skb_pp_cow_data() before exposing them to XDP, and only advertise XDP frags when the resulting skb has frags[]. skb_copy_bits() already handles frag_list input, and skb_pp_cow_data() builds frags[] output with skb_add_rx_frag(), which is the representation XDP multi-buffer expects.
Unified · Split
| @@ -756,7 +756,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, · 755 unmodified lines | |||
| 756 | u32 frame_sz; | 756 | u32 frame_sz; |
| 757 | 757 | ||
| 758 | if (skb_shared(skb) || skb_head_is_locked(skb) || | 758 | if (skb_shared(skb) || skb_head_is_locked(skb) || |
| 759 | skb_shinfo(skb)->nr_frags || | 759 | skb_is_nonlinear(skb) || |
| 760 | skb_headroom(skb) < XDP_PACKET_HEADROOM) { | 760 | skb_headroom(skb) < XDP_PACKET_HEADROOM) { |
| 761 | if (skb_pp_cow_data(rq->page_pool, pskb, XDP_PACKET_HEADROOM)) | 761 | if (skb_pp_cow_data(rq->page_pool, pskb, XDP_PACKET_HEADROOM)) |
| 762 | goto drop; | 762 | goto drop; |
| @@ -771,7 +771,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, · 8 unmodified lines | |||
| 771 | xdp_prepare_buff(xdp, skb->head, skb_headroom(skb), | 771 | xdp_prepare_buff(xdp, skb->head, skb_headroom(skb), |
| 772 | skb_headlen(skb), true); | 772 | skb_headlen(skb), true); |
| 773 | 773 | ||
| 774 | if (skb_is_nonlinear(skb)) { | 774 | if (skb_shinfo(skb)->nr_frags) { |
| 775 | skb_shinfo(skb)->xdp_frags_size = skb->data_len; | 775 | skb_shinfo(skb)->xdp_frags_size = skb->data_len; |
| 776 | xdp_buff_set_frags_flag(xdp); | 776 | xdp_buff_set_frags_flag(xdp); |
| 777 | } else { | 777 | } else { |
| @@ -927,6 +927,18 @@ static void skb_clone_fraglist(struct sk_buff *skb) · 926 unmodified lines | |||
| 927 | skb_get(list); | 927 | skb_get(list); |
| 928 | } | 928 | } |
| 929 | 929 | ||
| 930 | /** | ||
| 931 | * skb_pp_cow_data() - copy skb data into page-pool backed storage | ||
| 932 | * @pool: page pool to allocate from | ||
| 933 | * @pskb: pointer to skb pointer, replaced with the copied skb on success | ||
| 934 | * @headroom: headroom to reserve in the copied skb | ||
| 935 | * | ||
| 936 | * skb_copy_bits() handles both frags[] and frag_list input. If the copied | ||
| 937 | * skb remains non-linear, it uses frags[], which is the representation used | ||
| 938 | * by XDP multi-buffer. | ||
| 939 | * | ||
| 940 | * Return: 0 on success or a negative errno on failure. | ||
| 941 | */ | ||
| 930 | int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb, | 942 | int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb, |
| 931 | unsigned int headroom) | 943 | unsigned int headroom) |
| 932 | { | 944 | { |
| @@ -936,12 +948,6 @@ int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb, · 3 unmodified lines | |||
| 936 | int err, i, head_off; | 948 | int err, i, head_off; |
| 937 | void *data; | 949 | void *data; |
| 938 | 950 | ||
| 939 | /* XDP does not support fraglist so we need to linearize | ||
| 940 | * the skb. | ||
| 941 | */ | ||
| 942 | if (skb_has_frag_list(skb)) | ||
| 943 | return -EOPNOTSUPP; | ||
| 944 | |||
| 945 | max_head_size = SKB_WITH_OVERHEAD(PAGE_SIZE - headroom); | 951 | max_head_size = SKB_WITH_OVERHEAD(PAGE_SIZE - headroom); |
| 946 | if (skb->len > max_head_size + MAX_SKB_FRAGS * PAGE_SIZE) | 952 | if (skb->len > max_head_size + MAX_SKB_FRAGS * PAGE_SIZE) |
| 947 | return -ENOMEM; | 953 | return -ENOMEM; |