net: Avoid checksumming unreadable skb tail on trim
Subsystems (2)
PATCH 1/1 net: Avoid checksumming unreadable skb tail on trim
pskb_trim_rcsum_slow() keeps CHECKSUM_COMPLETE valid by subtracting the checksum of the bytes removed from the skb tail. That assumes the removed bytes can be read.
io_uring zcrx skbs may contain unreadable net_iov frags. With fbnic header/data split, small TCP/IPv4 packets can carry Ethernet padding in such a frag. ip_rcv_core() trims the skb to iph->tot_len before TCP sees it, and the CHECKSUM_COMPLETE adjustment then calls skb_checksum() on the padding.
This is exposed by IPv4 because small TCP/IPv4 frames can be shorter than the Ethernet minimum payload. TCP/IPv6 frames are large enough in the normal zcrx path, so they do not hit the same padding trim.
Keep the existing checksum adjustment for readable skbs. If the remaining packet is fully linear, drop CHECKSUM_COMPLETE and let the stack validate the packet after trimming. If unreadable payload would remain, fail the trim; the checksum cannot be adjusted without reading the trimmed tail.
Also clear skb->unreadable when trimming removes all frags.
--- net/core/skbuff.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
net/core/skbuff.c +27 -4
@@ -2787,6 +2787,8 @@ int ___pskb_trim(struct sk_buff *skb, unsigned int len) skb->data_len =0 ;skb_set_tail_pointer (skb, len); } +if (!skb_shinfo (skb)->nr_frags && !skb_has_frag_list (skb)) + skb->unreadable =0 ;if (!skb->sk || skb->destructor == sock_edemux)skb_condense (skb);
@@ -2794,16 +2796,37 @@ int ___pskb_trim(struct sk_buff *skb, unsigned int len) }EXPORT_SYMBOL (___pskb_trim); +static int pskb_trim_rcsum_complete (struct sk_buff *skb,unsigned int len) +{ +int delta = skb->len - len; + +if (skb_frags_readable (skb)) { + skb->csum =csum_block_sub (skb->csum, +skb_checksum (skb, len, delta,0 ), + len); +return 0 ; + } + +if (len >skb_headlen (skb)) +return -EFAULT ; + +/* The trimmed bytes are unreadable, but the remaining packet can be +* checksummed by software after trimming. +*/ + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} +/* Note : use pskb_trim_rcsum() instead of calling this directly */ int pskb_trim_rcsum_slow (struct sk_buff *skb,unsigned int len) {if (skb->ip_summed ==CHECKSUM_COMPLETE ) { -int delta = skb->len - len; +int err; - skb->csum =csum_block_sub (skb->csum, -skb_checksum (skb, len, delta,0 ), - len); + err =pskb_trim_rcsum_complete (skb, len); +if (err) +return err; }else if (skb->ip_summed ==CHECKSUM_PARTIAL ) {int hdlen = (len >skb_headlen (skb)) ?skb_headlen (skb) : len;int offset =skb_checksum_start_offset (skb) + skb->csum_offset;
base-commit: 68993ced0f618e36cf33388f1e50223e5e6e78cc
Signature · 1 line
2.54.0
Quoted 20 lines · Björn Töpel
pskb_trim_rcsum_slow()keepsCHECKSUM_COMPLETEvalid by subtracting the checksum of the bytes removed from the skb tail. That assumes the removed bytes can be read.
io_uringzcrx skbs may contain unreadablenet_iovfrags. With fbnic header/data split, small TCP/IPv4 packets can carry Ethernet padding in such a frag.ip_rcv_core()trims the skb toiph->tot_lenbefore TCP sees it, and theCHECKSUM_COMPLETEadjustment then callsskb_checksum()on the padding.This is exposed by IPv4 because small TCP/IPv4 frames can be shorter than the Ethernet minimum payload. TCP/IPv6 frames are large enough in the normal zcrx path, so they do not hit the same padding trim.
Keep the existing checksum adjustment for readable skbs. If the remaining packet is fully linear, drop
CHECKSUM_COMPLETEand let the stack validate the packet after trimming. If unreadable payload would remain, fail the trim; the checksum cannot be adjusted without reading the trimmed tail.
Quoted 4 lines
Also clear
skb->unreadablewhen trimming removes all frags.Fixes 65249feb6b3d ("net: add support for skbs with unreadable frags")Signed-off-by Björn Töpel <[email protected]>
net/core/skbuff.c int ___pskb_trim(struct sk_buff *skb, unsigned int len) · line 2801
Quoted 3 lines
net/core/skbuff.c +3
-0+static int pskb_trim_rcsum_complete (struct sk_buff *skb,unsigned int len) +{ +int delta = skb->len - len;
I suppose this is not unsigned/size_t because csum_block_sub() requires an 'int', is this right?
Quoted 2 lines
/* Note : use
pskb_trim_rcsum()instead of calling this directly
*/
I think you can make this a one-line comment, or just a proper kdoc.
Quoted 22 lines · Breno Leitao
Quoted 20 lines · Björn Töpel
pskb_trim_rcsum_slow()keepsCHECKSUM_COMPLETEvalid by subtracting the checksum of the bytes removed from the skb tail. That assumes the removed bytes can be read.
io_uringzcrx skbs may contain unreadablenet_iovfrags. With fbnic header/data split, small TCP/IPv4 packets can carry Ethernet padding in such a frag.ip_rcv_core()trims the skb toiph->tot_lenbefore TCP sees it, and theCHECKSUM_COMPLETEadjustment then callsskb_checksum()on the padding.This is exposed by IPv4 because small TCP/IPv4 frames can be shorter than the Ethernet minimum payload. TCP/IPv6 frames are large enough in the normal zcrx path, so they do not hit the same padding trim.
Keep the existing checksum adjustment for readable skbs. If the remaining packet is fully linear, drop
CHECKSUM_COMPLETEand let the stack validate the packet after trimming. If unreadable payload would remain, fail the trim; the checksum cannot be adjusted without reading the trimmed tail.
Quoted 6 lines
Quoted 4 lines
Also clear
skb->unreadablewhen trimming removes all frags.Fixes 65249feb6b3d ("net: add support for skbs with unreadable frags")Signed-off-by Björn Töpel <[email protected]>Reviewed-by Breno Leitao <[email protected]>
Thanks, Breno!
Quoted 6 lines
net/core/skbuff.c int ___pskb_trim(struct sk_buff *skb, unsigned int len) · line 2801
Quoted 3 lines
net/core/skbuff.c +3
-0+static int pskb_trim_rcsum_complete (struct sk_buff *skb,unsigned int len) +{ +int delta = skb->len - len;I suppose this is not unsigned/size_t because
csum_block_sub()requires an 'int', is this right?
Yup, both skb_checksum() length and csum_block_sub() offset are int, and it also keeps the existing parent function's local type unchanged after the move.
Quoted 4 lines
Quoted 2 lines
/* Note : use
pskb_trim_rcsum()instead of calling this directly
*/I think you can make this a one-line comment, or just a proper kdoc.
Yes, but note that this was not an addition from me. I can fix it up if there are more changes required!
Thanks!
Björn
Quoted 43 lines · Björn Töpel
Quoted 22 lines · Breno Leitao
Quoted 20 lines · Björn Töpel
pskb_trim_rcsum_slow()keepsCHECKSUM_COMPLETEvalid by subtracting the checksum of the bytes removed from the skb tail. That assumes the removed bytes can be read.
io_uringzcrx skbs may contain unreadablenet_iovfrags. With fbnic header/data split, small TCP/IPv4 packets can carry Ethernet padding in such a frag.ip_rcv_core()trims the skb toiph->tot_lenbefore TCP sees it, and theCHECKSUM_COMPLETEadjustment then callsskb_checksum()on the padding.This is exposed by IPv4 because small TCP/IPv4 frames can be shorter than the Ethernet minimum payload. TCP/IPv6 frames are large enough in the normal zcrx path, so they do not hit the same padding trim.
Keep the existing checksum adjustment for readable skbs. If the remaining packet is fully linear, drop
CHECKSUM_COMPLETEand let the stack validate the packet after trimming. If unreadable payload would remain, fail the trim; the checksum cannot be adjusted without reading the trimmed tail.Quoted 6 lines
Quoted 4 lines
Also clear
skb->unreadablewhen trimming removes all frags.Fixes 65249feb6b3d ("net: add support for skbs with unreadable frags")Signed-off-by Björn Töpel <[email protected]>Reviewed-by Breno Leitao <[email protected]>Thanks, Breno!
Quoted 6 lines
net/core/skbuff.c int ___pskb_trim(struct sk_buff *skb, unsigned int len) · line 2801
Quoted 3 lines
net/core/skbuff.c +3
-0+static int pskb_trim_rcsum_complete (struct sk_buff *skb,unsigned int len) +{ +int delta = skb->len - len;I suppose this is not unsigned/size_t because
csum_block_sub()requires an 'int', is this right?Yup, both
skb_checksum()length andcsum_block_sub()offset are int, and it also keeps the existing parent function's local type unchanged after the move.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
/* Note : use
pskb_trim_rcsum()instead of calling this directly
*/I think you can make this a one-line comment, or just a proper kdoc.
Yes, but note that this was not an addition from me. I can fix it up if there are more changes required!
oh, nevermind. I misread it.
Thanks
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Fri, 22 May 2026 14:06:40 +0200 you wrote:
pskb_trim_rcsum_slow()keepsCHECKSUM_COMPLETEvalid by subtracting the checksum of the bytes removed from the skb tail. That assumes the removed bytes can be read.
io_uringzcrx skbs may contain unreadablenet_iovfrags. With fbnic header/data split, small TCP/IPv4 packets can carry Ethernet padding in such a frag.ip_rcv_core()trims the skb toiph->tot_lenbefore TCP sees it, and theCHECKSUM_COMPLETEadjustment then callsskb_checksum()on the padding.[...]
Here is the summary with links:
- [net] net: Avoid checksumming unreadable skb tail on trim
https://git.kernel.org/netdev/net/c/2e357f002c61
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html