History

veth: convert frag_list skbs before running XDP

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.

Matt Fleming committed 3 months ago

Commit d0d64151 parent 817ff6e2 files · +14 −8Browse files

Unified · Split

2 files
  1. drivers/net/veth.c +2 −2
  2. net/core/skbuff.c +12 −6
drivers/net/veth.c+2−2
@@ -756,7 +756,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, · 755 unmodified lines
756756 u32 frame_sz;
757757
758758 if (skb_shared(skb) || skb_head_is_locked(skb) ||
759− skb_shinfo(skb)->nr_frags ||
759+ skb_is_nonlinear(skb) ||
760760 skb_headroom(skb) < XDP_PACKET_HEADROOM) {
761761 if (skb_pp_cow_data(rq->page_pool, pskb, XDP_PACKET_HEADROOM))
762762 goto drop;
@@ -771,7 +771,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, · 8 unmodified lines
771771 xdp_prepare_buff(xdp, skb->head, skb_headroom(skb),
772772 skb_headlen(skb), true);
773773
774− if (skb_is_nonlinear(skb)) {
774+ if (skb_shinfo(skb)->nr_frags) {
775775 skb_shinfo(skb)->xdp_frags_size = skb->data_len;
776776 xdp_buff_set_frags_flag(xdp);
777777 } else {
net/core/skbuff.c+12−6
@@ -927,6 +927,18 @@ static void skb_clone_fraglist(struct sk_buff *skb) · 926 unmodified lines
927927 skb_get(list);
928928 }
929929
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+ */
930942 int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,
931943 unsigned int headroom)
932944 {
@@ -936,12 +948,6 @@ int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb, · 3 unmodified lines
936948 int err, i, head_off;
937949 void *data;
938950
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−
945951 max_head_size = SKB_WITH_OVERHEAD(PAGE_SIZE - headroom);
946952 if (skb->len > max_head_size + MAX_SKB_FRAGS * PAGE_SIZE)
947953 return -ENOMEM;

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