xsk: fix memory corruptions in net/core/xdp.c
Subsystems (4)
PATCH v3 1/1 xsk: fix memory corruptions in net/core/xdp.c
From: Clément Lecigne <[email protected]>
Commit 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion") introduced a vulnerability in the handling of XDP_PASS for AF_XDP zero-copy frames.
Note: Currently, this specific AF_XDP zero-copy conversion path is only reachable from the drivers/net/ethernet/intel/ice and drivers/net/ethernet/intel/idpf drivers.
When building an skb, xdp_build_skb_from_zc() uses the chunk size (xdp->frame_sz) for the allocation. However, napi_build_skb() automatically reserves space at the end of the allocation for the skb_shared_info structure.
Most high performance UMEM applications use 4K chunks, where the corruption cannot happen. However, if the UMEM is configured with 2KB chunks (a very common configuration to maximize packet density in memory), a standard 1500 MTU packet will trigger the corruption because the required space exceeds the 2048 byte chunk size:
Headroom (256) + Packet (1514) + skb_shared_info (320) = 2090 bytes
Because 2090 bytes > 2048 bytes and __skb_put() does not perform bounds checking, the memcpy() writes past the available linear data area and corrupts the skb_shared_info structure. This can lead to arbitrary code execution if pointers like destructor_arg are overwritten.
Additionally, in xdp_copy_frags_from_zc(), the allocation size is set strictly to the fragment size (len), but the subsequent memcpy() uses LARGEST_ALIGN(len). This mismatch results in an out-of-bounds write of up to 7 bytes, which triggers KASAN warnings and is unsafe despite typical page pool allocator padding.
Fix the skb allocation in xdp_build_skb_from_zc() by dynamically calculating the exact truesize required using SKB_HEAD_ALIGN() to properly account for the headroom, the LARGEST_ALIGN(len), and the skb_shared_info overhead.
Fix the out-of-bounds write in xdp_copy_frags_from_zc() by rounding up the allocation request using LARGEST_ALIGN(len) to match the copy operation.
---
Changes since v2:
- Used LARGEST_ALIGN to calculate the len to account for the aligned memcpy.
- Fixed the commit message to include the idpf driver.
Changes since v1:
- Used SKB_HEAD_ALIGN to properly calculate the required allocation size including the skb_shared_info overhead.
- Re-ordered variable declarations.
---
net/core/xdp.c +6 -5
@@ -698,8 +698,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,for (u32 i =0 ; i < nr_frags; i++) {const skb_frag_t *frag = &xinfo->frags[i]; -u32 len =skb_frag_size (frag); -u32 offset, truesize = len; +u32 offset, len =skb_frag_size (frag); +u32 truesize =LARGEST_ALIGN (len);struct page *page; page =page_pool_dev_alloc (pp, &offset, &truesize);
@@ -738,9 +738,10 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,*/ struct sk_buff *xdp_build_skb_from_zc (struct xdp_buff *xdp) { +u32 headroom = xdp->data_meta - xdp->data_hard_start;const struct xdp_rxq_info *rxq = xdp->rxq; -u32 len = xdp->data_end - xdp->data_meta; -u32 truesize = xdp->frame_sz; +u32 len =LARGEST_ALIGN (xdp->data_end - xdp->data_meta); +u32 truesize =SKB_HEAD_ALIGN (headroom + len);struct sk_buff *skb =NULL ;struct page_pool *pp;int metalen;
@@ -762,7 +763,7 @@ struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp) }skb_mark_for_recycle (skb); -skb_reserve (skb, xdp->data_meta - xdp->data_hard_start); +skb_reserve (skb, headroom);memcpy (__skb_put (skb, len), xdp->data_meta,LARGEST_ALIGN (len));
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The patch incorrectly rounds up the SKB logical length (`len`), appending uninitialized garbage…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch incorrectly rounds up the SKB logical length (len), appending uninitialized garbage bytes to the packet and corrupting its size. --
commit 2b99f24545da4e2ce6d6317b4cc495604fb468a5
Author: Clément Lecigne <[email protected]>
xsk: fix memory corruptions in net/core/xdp.c
This commit fixes a buffer overflow in xdp_build_skb_from_zc() when using 2KB UMEM chunks by accurately calculating the required truesize, including SKB headroom and skb_shared_info overhead. It also fixes an out-of-bounds write in xdp_copy_frags_from_zc() by aligning the allocation request size with the memcpy operation.
Quoted 4 lines
net/core/xdp.c +0
-0
[ ... ]
net/core/xdp.c static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb, · line 743
Quoted 9 lines
net/core/xdp.c +2
-2@@ -738,9 +738,10 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,*/ struct sk_buff *xdp_build_skb_from_zc (struct xdp_buff *xdp) { +u32 headroom = xdp->data_meta - xdp->data_hard_start;const struct xdp_rxq_info *rxq = xdp->rxq; -u32 len = xdp->data_end - xdp->data_meta; -u32 truesize = xdp->frame_sz; +u32 len =LARGEST_ALIGN (xdp->data_end - xdp->data_meta);
[Severity: High]
Does redefining len with LARGEST_ALIGN() discard the exact packet payload length needed for correct SKB construction?
Quoted 4 lines
net/core/xdp.c +1
-0+u32 truesize =SKB_HEAD_ALIGN (headroom + len);struct sk_buff *skb =NULL ;struct page_pool *pp;int metalen;
[ ... ]
net/core/xdp.c struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp) · line 768
Quoted 8 lines
net/core/xdp.c +1
-1@@ -762,7 +763,7 @@ struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp) }skb_mark_for_recycle (skb); -skb_reserve (skb, xdp->data_meta - xdp->data_hard_start); +skb_reserve (skb, headroom);memcpy (__skb_put (skb, len), xdp->data_meta,LARGEST_ALIGN (len));
[Severity: High]
Will passing the improperly aligned len to __skb_put() incorrectly inflate the logical length of the constructed SKB?
If len is rounded up to the nearest LARGEST_ALIGN boundary, __skb_put() will increase skb->len and skb->tail beyond the actual valid payload length.
Could this cause the trailing bytes to contain uninitialized data from UMEM, leading to a potential info leak or data corruption when the SKB is forwarded?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 40 lines
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen. However, if the UMEM is configured with 2KB chunks (a very common configuration to maximize packet density in memory), a standard 1500 MTU packet will trigger the corruption because the required space exceeds the 2048 byte chunk size:
Headroom (256) + Packet (1514) +
skb_shared_info(320) = 2090 bytesBecause 2090 bytes > 2048 bytes and
__skb_put()does not perform bounds checking, thememcpy()writes past the available linear data area and corrupts theskb_shared_infostructure. This can lead to arbitrary code execution if pointers likedestructor_argare overwritten.Additionally, in
xdp_copy_frags_from_zc(), the allocation size is set strictly to the fragment size (len), but the subsequentmemcpy()usesLARGEST_ALIGN(len). This mismatch results in an out-of-bounds write of up to 7 bytes, which triggers KASAN warnings and is unsafe despite typical page pool allocator padding.Fix the skb allocation in
xdp_build_skb_from_zc()by dynamically calculating the exact truesize required usingSKB_HEAD_ALIGN()to properly account for the headroom, theLARGEST_ALIGN(len), and theskb_shared_infooverhead.
Quoted 8 lines
Fix the out-of-bounds write in
xdp_copy_frags_from_zc()by rounding up the allocation request usingLARGEST_ALIGN(len)to match the copy operation.Fixes 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")CC Alexander Lobakin <[email protected]>CC Eric Dumazet <[email protected]>Signed-off-by Clément Lecigne <[email protected]>
Hi Clement,
Do you have a reproducer for mentioned issue or is it only a fix from theoretical POV?
To be clear, we were addressing headroom issues in this series:
https://lore.kernel.org/bpf/[email protected]/
so I wanted to ask if you are able to have this malformed setup for 2k chunk size. That series should not allow for that.
I think this is the second time someone is trying to fix this area of code, so it is not a nack or something, let us fix this, but I wanted to have us on the same page.
Thanks,
Maciej
Quoted 53 lines
---
Changes since v2:
- UsedLARGEST_ALIGNto calculate the len to account for the aligned
memcpy.
- Fixed the commit message to include the idpf driver.Changes since v1:
- UsedSKB_HEAD_ALIGNto properly calculate the required allocation size including theskb_shared_infooverhead.
- Re-ordered variable declarations.---
net/core/xdp.c +2
-2@@ -698,8 +698,8 @@ static noinline bool xdp_copy_frags_from_zc(structsk_buff *skb, for (u32 i = 0; i < nr_frags; i++) {const skb_frag_t *frag = &xinfo->frags[i]; -u32 len =skb_frag_size (frag); -u32 offset, truesize = len; +u32 offset, len =skb_frag_size (frag); +u32 truesize =LARGEST_ALIGN (len);struct page *page;net/core/xdp.c +3
-2page =page_pool_dev_alloc (pp, &offset, &truesize);@@ -738,9 +738,10 @@ static noinline bool xdp_copy_frags_from_zc(structsk_buff *skb, */ struct sk_buff *xdp_build_skb_from_zc (struct xdp_buff *xdp) { +u32 headroom = xdp->data_meta - xdp->data_hard_start;const struct xdp_rxq_info *rxq = xdp->rxq; -u32 len = xdp->data_end - xdp->data_meta; -u32 truesize = xdp->frame_sz; +u32 len =LARGEST_ALIGN (xdp->data_end - xdp->data_meta); +u32 truesize =SKB_HEAD_ALIGN (headroom + len);struct sk_buff *skb =NULL ;struct page_pool *pp;net/core/xdp.c +1
-1int metalen;@@ -762,7 +763,7 @@ struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp) }skb_mark_for_recycle (skb); -skb_reserve (skb, xdp->data_meta - xdp->data_hard_start); +skb_reserve (skb, headroom); memcpy(__skb_put(skb, len), xdp->data_meta,
LARGEST_ALIGN(len));
Quoted 52 lines · Maciej
Quoted 41 lines
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen. However, if the UMEM is configured with 2KB chunks (a very common configuration to maximize packet density in memory), a standard 1500 MTU packet will trigger the corruption because the required space exceeds the 2048 byte chunk size:
Headroom (256) + Packet (1514) +
skb_shared_info(320) = 2090 bytesBecause 2090 bytes > 2048 bytes and
__skb_put()does not perform bounds checking, thememcpy()writes past the available linear data area and corrupts theskb_shared_infostructure. This can lead to arbitrary code execution if pointers likedestructor_argare overwritten.Additionally, in
xdp_copy_frags_from_zc(), the allocation size is set strictly to the fragment size (len), but the subsequentmemcpy()usesLARGEST_ALIGN(len). This mismatch results in an out-of-bounds write of up to 7 bytes, which triggers KASAN warnings and is unsafe despite typical page pool allocator padding.Fix the skb allocation in
xdp_build_skb_from_zc()by dynamically calculating the exact truesize required usingSKB_HEAD_ALIGN()to properly account for the headroom, theLARGEST_ALIGN(len), and theskb_shared_infooverhead.Quoted 8 lines
Fix the out-of-bounds write in
xdp_copy_frags_from_zc()by rounding up the allocation request usingLARGEST_ALIGN(len)to match the copy operation.Fixes 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")CC Alexander Lobakin <[email protected]>CC Eric Dumazet <[email protected]>Signed-off-by Clément Lecigne <[email protected]>Hi Clement,
Quoted 8 lines
Do you have a reproducer for mentioned issue or is it only a fix from theoretical POV?
To be clear, we were addressing headroom issues in this series:
https://lore.kernel.org/bpf/[email protected]/so I wanted to ask if you are able to have this malformed setup for 2k chunk size. That series should not allow for that.
I didn't manage to build a malformed setup and only used a LKM to reproduce the issue artificially. I shared some more details with you privately.
Thanks,
-clem
Quoted 62 lines
I think this is the second time someone is trying to fix this area of code, so it is not a nack or something, let us fix this, but I wanted to have us on the same page.
Thanks,
MaciejQuoted 53 lines
---
Changes since v2:
- UsedLARGEST_ALIGNto calculate the len to account for the aligned
memcpy.
- Fixed the commit message to include the idpf driver.Changes since v1:
- UsedSKB_HEAD_ALIGNto properly calculate the required allocation size including theskb_shared_infooverhead.
- Re-ordered variable declarations.---
net/core/xdp.c +2
-2@@ -698,8 +698,8 @@ static noinline bool xdp_copy_frags_from_zc(structsk_buff *skb, for (u32 i = 0; i < nr_frags; i++) {const skb_frag_t *frag = &xinfo->frags[i]; -u32 len =skb_frag_size (frag); -u32 offset, truesize = len; +u32 offset, len =skb_frag_size (frag); +u32 truesize =LARGEST_ALIGN (len);struct page *page;page = page_pool_dev_alloc(pp, &offset, &truesize);net/core/xdp.c +3
-2@@ -738,9 +738,10 @@ static noinline bool xdp_copy_frags_from_zc(structsk_buff *skb, */ struct sk_buff *xdp_build_skb_from_zc (struct xdp_buff *xdp) { +u32 headroom = xdp->data_meta - xdp->data_hard_start;const struct xdp_rxq_info *rxq = xdp->rxq; -u32 len = xdp->data_end - xdp->data_meta; -u32 truesize = xdp->frame_sz; +u32 len =LARGEST_ALIGN (xdp->data_end - xdp->data_meta); +u32 truesize =SKB_HEAD_ALIGN (headroom + len);struct sk_buff *skb =NULL ;struct page_pool *pp;int metalen;net/core/xdp.c +1
-1@@ -762,7 +763,7 @@ struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp) }skb_mark_for_recycle (skb); -skb_reserve (skb, xdp->data_meta - xdp->data_hard_start); +skb_reserve (skb, headroom); memcpy(__skb_put(skb, len), xdp->data_meta,
LARGEST_ALIGN(len));
Paolo Abeni
maintainerQuoted 57 lines · Clement Lecigne
Quoted 55 lines · Maciej
Quoted 41 lines
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen. However, if the UMEM is configured with 2KB chunks (a very common configuration to maximize packet density in memory), a standard 1500 MTU packet will trigger the corruption because the required space exceeds the 2048 byte chunk size:
Headroom (256) + Packet (1514) +
skb_shared_info(320) = 2090 bytesBecause 2090 bytes > 2048 bytes and
__skb_put()does not perform bounds checking, thememcpy()writes past the available linear data area and corrupts theskb_shared_infostructure. This can lead to arbitrary code execution if pointers likedestructor_argare overwritten.Additionally, in
xdp_copy_frags_from_zc(), the allocation size is set strictly to the fragment size (len), but the subsequentmemcpy()usesLARGEST_ALIGN(len). This mismatch results in an out-of-bounds write of up to 7 bytes, which triggers KASAN warnings and is unsafe despite typical page pool allocator padding.Fix the skb allocation in
xdp_build_skb_from_zc()by dynamically calculating the exact truesize required usingSKB_HEAD_ALIGN()to properly account for the headroom, theLARGEST_ALIGN(len), and theskb_shared_infooverhead.Quoted 8 lines
Fix the out-of-bounds write in
xdp_copy_frags_from_zc()by rounding up the allocation request usingLARGEST_ALIGN(len)to match the copy operation.Fixes 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")CC Alexander Lobakin <[email protected]>CC Eric Dumazet <[email protected]>Signed-off-by Clément Lecigne <[email protected]>Hi Clement,
Do you have a reproducer for mentioned issue or is it only a fix from theoretical POV?
Quoted 8 lines
Quoted 5 lines
To be clear, we were addressing headroom issues in this series:
https://lore.kernel.org/bpf/[email protected]/so I wanted to ask if you are able to have this malformed setup for 2k chunk size. That series should not allow for that.
I didn't manage to build a malformed setup and only used a LKM to reproduce the issue artificially.
Note that we don't accept patches addressing issue for OoT modules. I read you reply as the critical setup can't be obtained with the vanilla tree.
Please clarify otherwise.
/P
Waking a dead thread: RISE FROM YOUR GRAVE!
Quoted 5 lines · Clement Lecigne
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.
Hmm, I acually hit this in my WIP for UMEM page pool provider hack.
Quoted 11 lines
Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen.
I think this can also happen with 4K UMEM chunks.
For example, on ice, use MTU 3800, 4K chunks, and no extra UMEM headroom. Attach an xdp.frags program that returns XDP_PASS, and bind the socket without XDP_USE_SG.
A 3814-byte Ethernet frame fits in the UMEM chunk:
256 headroom + 3814 packet = 4070 bytes
But the copied skb also needs space for skb_shared_info. Using the 320-byte size from your example:
256 headroom + 3814 packet + 320 shared info = 4390 bytes
The old code allocates only 4096 bytes, so the packet copy overwrites skb_shared_info.
Am I missing something?
Björn
Quoted 37 lines · Björn Töpel
Waking a dead thread: RISE FROM YOUR GRAVE!
Quoted 5 lines · Clement Lecigne
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.Hmm, I acually hit this in my WIP for UMEM page pool provider hack.
Quoted 11 lines
Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen.
I think this can also happen with 4K UMEM chunks.
For example, on ice, use MTU 3800, 4K chunks, and no extra UMEM headroom. Attach an xdp.frags program that returns
XDP_PASS, and bind the socket withoutXDP_USE_SG.A 3814-byte Ethernet frame fits in the UMEM chunk:
256 headroom + 3814 packet = 4070 bytes
But the copied skb also needs space for
skb_shared_info. Using the 320-byte size from your example:
Quoted 6 lines
256 headroom + 3814 packet + 320 shared info = 4390 bytes
The old code allocates only 4096 bytes, so the packet copy overwrites
skb_shared_info.Am I missing something?
I was pushing back on relying on scenario above as we respect the tailroom now since some time:
Quoted 3 lines
Björn
Quoted 43 lines · Maciej Fijalkowski
Quoted 42 lines · Björn Töpel
Waking a dead thread: RISE FROM YOUR GRAVE!
Quoted 5 lines · Clement Lecigne
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.Hmm, I acually hit this in my WIP for UMEM page pool provider hack.
Quoted 11 lines
Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen.
I think this can also happen with 4K UMEM chunks.
For example, on ice, use MTU 3800, 4K chunks, and no extra UMEM headroom. Attach an xdp.frags program that returns
XDP_PASS, and bind the socket withoutXDP_USE_SG.A 3814-byte Ethernet frame fits in the UMEM chunk:
256 headroom + 3814 packet = 4070 bytes
But the copied skb also needs space for
skb_shared_info. Using the 320-byte size from your example:256 headroom + 3814 packet + 320 shared info = 4390 bytes
The old code allocates only 4096 bytes, so the packet copy overwrites
skb_shared_info.
Quoted 8 lines
Quoted 1 line
Am I missing something?
I was pushing back on relying on scenario above as we respect the tailroom now since some time:
Hmm, isn't that only with XDP_USE_SG? My example binds without it.
Then xsk_pool_get_rx_frame_size() returns 3840. XDP_PASS still builds an skb with skb_shared_info, even if it's linear. So we only have 4096 - 256 - 320 = 3520 bytes for the packet.
Or am I missing another check?
Quoted 54 lines · Björn Töpel
Quoted 43 lines · Maciej Fijalkowski
Quoted 42 lines · Björn Töpel
Waking a dead thread: RISE FROM YOUR GRAVE!
Quoted 5 lines · Clement Lecigne
From: Clément Lecigne <[email protected]>
Commit
560d958c6c68("xsk: add generic XSk&xdp_buff-> skb conversion") introduced a vulnerability in the handling ofXDP_PASSforAF_XDPzero-copy frames.Hmm, I acually hit this in my WIP for UMEM page pool provider hack.
Quoted 11 lines
Note: Currently, this specific
AF_XDPzero-copy conversion path is only reachable from thedrivers/net/ethernet/intel/iceanddrivers/net/ethernet/intel/idpfdrivers.When building an skb,
xdp_build_skb_from_zc()uses the chunk size (xdp->frame_sz) for the allocation. However,napi_build_skb()automatically reserves space at the end of the allocation for theskb_shared_infostructure.Most high performance UMEM applications use 4K chunks, where the corruption cannot happen.
I think this can also happen with 4K UMEM chunks.
For example, on ice, use MTU 3800, 4K chunks, and no extra UMEM headroom. Attach an xdp.frags program that returns
XDP_PASS, and bind the socket withoutXDP_USE_SG.A 3814-byte Ethernet frame fits in the UMEM chunk:
256 headroom + 3814 packet = 4070 bytes
But the copied skb also needs space for
skb_shared_info. Using the 320-byte size from your example:256 headroom + 3814 packet + 320 shared info = 4390 bytes
The old code allocates only 4096 bytes, so the packet copy overwrites
skb_shared_info.Quoted 8 lines
Quoted 1 line
Am I missing something?
I was pushing back on relying on scenario above as we respect the tailroom now since some time:
Quoted 7 lines
Hmm, isn't that only with
XDP_USE_SG? My example binds without it.Then
xsk_pool_get_rx_frame_size()returns 3840.XDP_PASSstill builds an skb withskb_shared_info, even if it's linear. So we only have 4096 - 256 - 320 = 3520 bytes for the packet.Or am I missing another check?
I missed your trick with xdp.frags on prog side. Get this fixed then! :D I had a thought like 'who cares if we overwrite struct not used in linear traffic' but as Clement said somewhere destructor_arg overwrite would make a mess.
Side note is ice currently still only allows 3k buffers for linear XDP progs but it currently works with page_pool not with magic page split mechanism, so the limit should be lifted.
I might take this as an AR but anyone reading this in future feel free to pick it up.
Bjorn, let us see if Clement responses in some nearby future, otherwise please go forward and submit a standalone fix out of your series.
Thanks!
Quoted 4 lines · Maciej Fijalkowski
Quoted 1 line
Or am I missing another check?
I missed your trick with xdp.frags on prog side. Get this fixed then! :D I
...so many bugs... ;)
Quoted 8 lines
had a thought like 'who cares if we overwrite struct not used in linear traffic' but as Clement said somewhere
destructor_argoverwrite would make a mess.Side note is ice currently still only allows 3k buffers for linear XDP progs but it currently works with
page_poolnot with magic page split mechanism, so the limit should be lifted.
Quoted 5 lines
I might take this as an AR but anyone reading this in future feel free to pick it up.
Bjorn, let us see if Clement responses in some nearby future, otherwise please go forward and submit a standalone fix out of your series.
SG!
Björn