bpf, xdp, i40e: fix i40e_build_skb skb reserve and truesize
Subsystems (3)
PATCH 1/1 bpf, xdp, i40e: fix i40e_build_skb skb reserve and truesize
Using skb_reserve(skb, I40E_SKB_PAD + (xdp->data - xdp->data_hard_start)) is clearly wrong since I40E_SKB_PAD already points to the offset where the original xdp->data was sitting since xdp->data_hard_start is defined as xdp->data - i40e_rx_offset(rx_ring) where latter offsets to I40E_SKB_PAD when build skb is used.
However, also before cc5b114dcf98 ("bpf, i40e: add meta data support") this seems broken since bpf_xdp_adjust_head() helper could have been used to alter headroom and enlarge / shrink the frame and with that the assumption that the xdp->data remains unchanged does not hold and would push a bogus packet to upper stack.
ixgbe got this right in 924708081629 ("ixgbe: add XDP support for pass and drop actions"). In any case, fix it by removing the I40E_SKB_PAD from both skb_reserve() and truesize calculation.
--- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_txrx.c +3 -4
@@ -2103,9 +2103,8 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,unsigned int truesize =i40e_rx_pg_size (rx_ring) /2 ;#else unsigned int truesize =SKB_DATA_ALIGN (sizeof (struct skb_shared_info )) + -SKB_DATA_ALIGN (I40E_SKB_PAD + - (xdp->data_end - - xdp->data_hard_start)); +SKB_DATA_ALIGN (xdp->data_end - + xdp->data_hard_start);#endif struct sk_buff *skb;
@@ -2124,7 +2123,7 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,return NULL ;/* update pointers within the skb to store the data */ -skb_reserve (skb,I40E_SKB_PAD + (xdp->data - xdp->data_hard_start)); +skb_reserve (skb, xdp->data - xdp->data_hard_start);__skb_put (skb, xdp->data_end - xdp->data);if (metasize)skb_metadata_set (skb, metasize);
Signature · 1 line
2.9.5
Quoted 16 lines · Daniel Borkmann
Using
skb_reserve(skb, I40E_SKB_PAD + (xdp->data - xdp->data_hard_start))is clearly wrong sinceI40E_SKB_PADalready points to the offset where the originalxdp->datawas sitting sincexdp->data_hard_startis defined asxdp->data-i40e_rx_offset(rx_ring)where latter offsets toI40E_SKB_PADwhen build skb is used.However, also before
cc5b114dcf98("bpf, i40e: add meta data support") this seems broken sincebpf_xdp_adjust_head()helper could have been used to alter headroom and enlarge / shrink the frame and with that the assumption that thexdp->dataremains unchanged does not hold and would push a bogus packet to upper stack.ixgbe got this right in 924708081629 ("ixgbe: add XDP support for pass and drop actions"). In any case, fix it by removing the
I40E_SKB_PADfrom bothskb_reserve()and truesize calculation.
Quoted 7 lines
Fixes cc5b114dcf98 ("bpf, i40e: add meta data support")Fixes 0c8493d90b6b ("i40e: add XDP support for pass and drop actions")Reported-by Keith Busch <[email protected]>Reported-by Toshiaki Makita <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>Cc Björn Töpel <[email protected]>Cc John Fastabend <[email protected]>
Thanks for the quick fix! This works for me.
Quoted 23 lines · Daniel Borkmann
Using
skb_reserve(skb, I40E_SKB_PAD + (xdp->data - xdp->data_hard_start))is clearly wrong sinceI40E_SKB_PADalready points to the offset where the originalxdp->datawas sitting sincexdp->data_hard_startis defined asxdp->data-i40e_rx_offset(rx_ring)where latter offsets toI40E_SKB_PADwhen build skb is used.However, also before
cc5b114dcf98("bpf, i40e: add meta data support") this seems broken sincebpf_xdp_adjust_head()helper could have been used to alter headroom and enlarge / shrink the frame and with that the assumption that thexdp->dataremains unchanged does not hold and would push a bogus packet to upper stack.ixgbe got this right in 924708081629 ("ixgbe: add XDP support for pass and drop actions"). In any case, fix it by removing the
I40E_SKB_PADfrom bothskb_reserve()and truesize calculation.Fixes cc5b114dcf98 ("bpf, i40e: add meta data support")Fixes 0c8493d90b6b ("i40e: add XDP support for pass and drop actions")Reported-by Keith Busch <[email protected]>Reported-by Toshiaki Makita <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>Cc Bj?rn T?pel <[email protected]>Cc John Fastabend <[email protected]>
Quoted 4 lines
--- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Thanks! I missed this during review.
Alexander Duyck
Acked-byQuoted 29 lines · John Fastabend
Quoted 23 lines · Daniel Borkmann
Using
skb_reserve(skb, I40E_SKB_PAD + (xdp->data - xdp->data_hard_start))is clearly wrong sinceI40E_SKB_PADalready points to the offset where the originalxdp->datawas sitting sincexdp->data_hard_startis defined asxdp->data-i40e_rx_offset(rx_ring)where latter offsets toI40E_SKB_PADwhen build skb is used.However, also before
cc5b114dcf98("bpf, i40e: add meta data support") this seems broken sincebpf_xdp_adjust_head()helper could have been used to alter headroom and enlarge / shrink the frame and with that the assumption that thexdp->dataremains unchanged does not hold and would push a bogus packet to upper stack.ixgbe got this right in 924708081629 ("ixgbe: add XDP support for pass and drop actions"). In any case, fix it by removing the
I40E_SKB_PADfrom bothskb_reserve()and truesize calculation.Fixes cc5b114dcf98 ("bpf, i40e: add meta data support")Fixes 0c8493d90b6b ("i40e: add XDP support for pass and drop actions")Reported-by Keith Busch <[email protected]>Reported-by Toshiaki Makita <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>Cc Bj?rn T?pel <[email protected]>Cc John Fastabend <[email protected]>Quoted 4 lines
--- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 3 lines
Thanks! I missed this during review.
Acked-by John Fastabend <[email protected]>
Looks good to me. Thanks for taking care of this.