net: skbuff: follow-ups to the BUG_ON() removal
Subsystems (9)
cover net: skbuff: follow-ups to the BUG_ON() removal
Hello,
Jakub applied v2 of my skbuff BUG_ON() series[1] before I got v3 out, so this is what v3 would have changed, as fixes on top of what landed, plus the skb_copy_and_csum_bits() patch I'd been sending to net on its own.
Patch 1 is that patch[2], moved to net-next as Mina suggested, with his Reviewed-by. It makes skb_copy_and_csum_bits() report failure, and the rest of the series builds on it. Please drop the net version.
Patches 2 through 6 deal with skb_checksum() and skb_crc32c(). My v2 had them return 0 when they run out of skb, and that turned out not to be safe: 0 is a valid checksum, and it can make a packet that was never fully checksummed pass verification. So they get versions that report failure, skb_checksum_full() and skb_crc32c_full(), and the core users switch to them: checksum validation now rejects a packet it can't checksum, skb_segment() and pskb_trim_rcsum() fail instead of using a bad sum, and skb_crc32c_csum_help() drops the packet. skb_checksum() and skb_crc32c() stay as wrappers that behave as before, and I'll convert the rest of their callers per subsystem in later series.
Patches 7 through 10 fix problems Sashiko and an LLM review found in what was applied. skb_zerocopy() refuses a zero-length copy that Open vSwitch can trigger from a user namespace, skb_try_coalesce() and skb_copy_and_csum_bits() can be handed a negative length, and skb_headlen() can underflow in skb_copy_and_csum_dev().
Patches 11 and 12 make skb_segment() refuse a nested frag_list, which could still oops on a NULL list_skb, and add KUnit cases for the layouts it refuses. Patches 13 and 14 get rid of the same BUG_ON()s in xen-netfront's bounce_skb() and tls's __skb_nsg(), and patch 15 updates comments that still describe the old BUG_ON()s.
I tested this with the net_core KUnit tests, a test module that drives each of these paths under KASAN and fault injection, an Open vSwitch reproducer for patch 7, and a stress run over veth with netem. Thanks,
Josef
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/20261013-b4-skb-segment-nosg-unreadable-v2-1-6c28d8ffa51e@toxicpanda.com/
---
Josef Bacik (15):
net: skbuff: make skb_copy_and_csum_bits() report unreadable frags
net: skbuff: add skb_checksum_full() that reports failure
net: skbuff: fail checksum validation when the skb can't be checksummed
net: skbuff: fail segmentation when a segment can't be checksummed
net: skbuff: fail pskb_trim_rcsum() when it can't checksum the tail
net: skbuff: add skb_crc32c_full() that reports failure
net: skbuff: let skb_zerocopy() copy a short skb without head_frag
net: skbuff: make skb_try_coalesce()'s len unsigned
net: skbuff: check csum_start against len in skb_copy_and_csum_dev()
net: skbuff: reject a negative length in skb_copy_and_csum_bits()
net: skbuff: refuse to segment a nested frag_list
net: test the frag_list layouts skb_segment() refuses
xen-netfront: don't BUG() when skb_copy_bits() fails in bounce_skb() net/tls: don't BUG() on leftover length in __skb_nsg()
net: update comments that still describe the skb BUG_ON()s
drivers/net/ethernet/sun/sunvnet_common.c | 10 +- drivers/net/xen-netfront.c | 7 +- include/linux/skbuff.h | 8 +- net/core/dev.c | 7 +- net/core/filter.c | 6 +- net/core/net_test.c | 52 +++++- net/core/skbuff.c | 274 +++++++++++++++++++++++------- net/ipv4/icmp.c | 9 +- net/ipv4/ip_output.c | 11 +- net/ipv6/icmp.c | 7 +- net/ipv6/ip6_output.c | 11 +- net/sunrpc/socklib.c | 9 +- net/tls/tls_sw.c | 5 +- 13 files changed, 327 insertions(+), 89 deletions(-)
---
base-commit: 6b3e73774815910a39d8ca75b9ad7df963f61d50
change-id: 20261016-b4-skbuff-bug-on-followups-ad11adf285a4
PATCH 1/15 net: skbuff: make skb_copy_and_csum_bits() report unreadable frags
skb_copy_and_csum_bits() has no way to fail. When it reaches unreadable frags it zero-fills the rest of the buffer and returns 0, and since commit ab9414ed70bd ("net: skbuff: don't leave stale bytes in skb_copy_and_csum_bits()") that 0 is the correct checksum for what's in the buffer. Its callers can't tell the copy didn't happen.
That matters in the !sg && !csum branch of skb_segment(). A devmem TCP skb keeps its whole payload in unreadable frags, so every segment ends up with a payload of zeroes, tcp_gso_segment() writes a valid TCP checksum over it, and the peer accepts the zeroes as stream data. This is reachable when both SG and TX checksum offload are turned off on a device used for devmem TX: sk_setup_caps() still gives TCP SG and HW_CSUM, so the dmabuf send is accepted, validate_xmit_unreadable_skb() lets the skb through for a NETMEM_TX_NO_DMA device or a matching binding, and software GSO segments it with neither feature. Before that commit the segments carried uninitialized memory with a checksum that almost never matched.
This was reproduced with a test module rather than on devmem hardware:skb_segment() on a TCPv4 GSO skb with 3000 bytes of payload in a page frag marked unreadable, with features == 0, returns 3 segments whose payloads are all zeroes, each with a checksum of 0, which is correct for zeroes. There's no warning or error; the data is silently replaced. With this patch skb_segment() returns -EFAULT.
Make skb_copy_and_csum_bits() return 0 or -EFAULT and hand the checksum back through a pointer, and make it __must_check so a new caller can't ignore the failure. Running out of skb before @len returns -EFAULT too; commit 417261779eab ("net: skbuff: don't BUG() on leftover length in skb_copy_and_csum_bits()") made that a zero-fill and a checksum of 0. Each caller takes the error path it already has for a failed copy:
- skb_segment() fails the segmentation, as the csum branch already does when skb_copy_bits() fails.
- icmp_glue_bits() and icmpv6_getfrag() return the error, so the ICMP error isn't sent.
- __ip_append_data() and __ip6_append_data() drop the new skb and return -EFAULT, as they do when getfrag fails.
- vnet_skb_shape() fails the same way it does when its skb_copy_bits() call fails.
- xdr_skb_read_bits() returns 0 without consuming anything, as it does when skb_copy_bits() fails, so desc.count stays non-zero and csum_partial_copy_to_xdr() fails. csum_partial_copy_to_xdr() used to checksum the bytes it hadn't copied before checking desc.count. desc.offset and desc.count always add up to skb->len, so that only ran when it was about to fail anyway, and on an unreadable skb skb_checksum() would WARN. Drop it.
- skb_copy_and_csum_dev() can't return an error, so it leaves the checksum alone and the frame goes out with a bad one. Its callers are drivers that never see unreadable skbs anyway.
The zero-fill stays, so a caller that does send the buffer still doesn't leak anything.
This was found by the Sashiko AI review of that commit, and Mina suggested reporting the error from the helper rather than checking for unreadable frags in skb_segment().
--- drivers/net/ethernet/sun/sunvnet_common.c | 10 +++-- include/linux/skbuff.h | 4 +- net/core/skbuff.c | 63 +++++++++++++++++++++---------- net/ipv4/icmp.c | 9 +++-- net/ipv4/ip_output.c | 11 ++++-- net/ipv6/icmp.c | 7 +++- net/ipv6/ip6_output.c | 11 ++++-- net/sunrpc/socklib.c | 9 ++--- 8 files changed, 83 insertions(+), 41 deletions(-)
drivers/net/ethernet/sun/sunvnet_common.c +7 -3
@@ -1167,9 +1167,13 @@ static inline struct sk_buff *vnet_skb_shape(struct sk_buff *skb, int ncookies)/* copy the rest, with csum calculation */ *(__sum16 *)(skb->data + offset) =0 ; - csum =skb_copy_and_csum_bits (skb, start, - nskb->data + start, - skb->len - start); +if (skb_copy_and_csum_bits (skb, start, + nskb->data + start, + skb->len - start, &csum)) { +dev_kfree_skb (nskb); +dev_kfree_skb (skb); +return NULL ; + }/* add in the header checksums */ if (skb->protocol ==htons (ETH_P_IP )) {
include/linux/skbuff.h +2 -2
@@ -4277,8 +4277,8 @@ void skb_free_datagram(struct sock *sk, struct sk_buff *skb);int skb_kill_datagram (struct sock *sk,struct sk_buff *skb,unsigned int flags);int skb_copy_bits (const struct sk_buff *skb,int offset,void *to,int len);int skb_store_bits (struct sk_buff *skb,int offset,const void *from,int len); -__wsum skb_copy_and_csum_bits (const struct sk_buff *skb,int offset,u8 *to, -int len); +int __must_check skb_copy_and_csum_bits (const struct sk_buff *skb,int offset, +u8 *to,int len,__wsum *csum);int skb_splice_bits (struct sk_buff *skb,struct sock *sk,unsigned int offset,struct pipe_inode_info *pipe,unsigned int len,unsigned int flags);
net/core/skbuff.c +44 -19
120 lines not on this page · raw message
net/ipv4/icmp.c +6 -3
@@ -364,12 +364,15 @@ static int icmp_glue_bits(void *from, char *to, int offset, int len, int odd, DEFINE_RAW_FLEX(struct icmp_bxm, icmp_param, replyopts.opt.__data, IP_OPTIONS_DATA_FIXED_SIZE);__wsum csum; +int err; icmp_param = from; - csum =skb_copy_and_csum_bits (icmp_param->skb, - icmp_param->offset + offset, - to, len); + err =skb_copy_and_csum_bits (icmp_param->skb, + icmp_param->offset + offset, + to, len, &csum); +if (err) +return err; skb->csum =csum_block_add (skb->csum, csum, odd); if (icmp_param->data.icmph.type <= NR_ICMP_TYPES &&
net/ipv4/ip_output.c +8 -3
@@ -1162,9 +1162,14 @@ static int __ip_append_data(struct sock *sk, data += fragheaderlen + exthdrlen;if (fraggap) { - skb->csum =skb_copy_and_csum_bits ( - skb_prev, maxfraglen, - data + transhdrlen, fraggap); +if (skb_copy_and_csum_bits (skb_prev, maxfraglen, + data + transhdrlen, + fraggap, + &skb->csum)) { + err = -EFAULT ; +kfree_skb (skb); + goto error; + } skb_prev->csum =csum_sub (skb_prev->csum, skb->csum); data += fraggap;
net/ipv6/icmp.c +5 -2
@@ -322,9 +322,12 @@ static int icmpv6_getfrag(void *from, char *to, int offset, int len, int odd, ststruct icmpv6_msg *msg = (struct icmpv6_msg *) from;struct sk_buff *org_skb = msg->skb;__wsum csum; +int err; - csum =skb_copy_and_csum_bits (org_skb, msg->offset + offset, - to, len); + err =skb_copy_and_csum_bits (org_skb, msg->offset + offset, + to, len, &csum); +if (err) +return err; skb->csum =csum_block_add (skb->csum, csum, odd);if (!(msg->type &ICMPV6_INFOMSG_MASK ))nf_ct_attach (skb, org_skb);
net/ipv6/ip6_output.c +8 -3
@@ -1724,9 +1724,14 @@ static int __ip6_append_data(struct sock *sk, skb->transport_header = (skb->network_header + fragheaderlen);if (fraggap) { - skb->csum =skb_copy_and_csum_bits ( - skb_prev, maxfraglen, - data + transhdrlen, fraggap); +if (skb_copy_and_csum_bits (skb_prev, maxfraglen, + data + transhdrlen, + fraggap, + &skb->csum)) { + err = -EFAULT ; +kfree_skb (skb); + goto error; + } skb_prev->csum =csum_sub (skb_prev->csum, skb->csum); data += fraggap;
net/sunrpc/socklib.c +3 -6
@@ -49,7 +49,9 @@ xdr_skb_read_bits(struct xdr_skb_reader *desc, void *to, size_t len)if (desc->need_checksum) {__wsum csum; - csum =skb_copy_and_csum_bits (desc->skb, desc->offset, to, len); +if (unlikely (skb_copy_and_csum_bits (desc->skb, desc->offset, + to, len, &csum))) +return 0 ; desc->csum =csum_block_add (desc->csum, csum, desc->offset); }else {if (unlikely (skb_copy_bits (desc->skb, desc->offset, to, len)))
@@ -142,11 +144,6 @@ int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb) desc.csum =csum_partial (skb->data, desc.offset, skb->csum);if (xdr_partial_copy_from_skb (xdr, &desc) <0 )return -1 ; -if (desc.offset != skb->len) { -__wsum csum2; - csum2 =skb_checksum (skb, desc.offset, skb->len - desc.offset,0 ); - desc.csum =csum_block_add (desc.csum, csum2, desc.offset); - }if (desc.count)return -1 ;if (csum_fold (desc.csum))
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 01/15] net: skbuff: make skb_copy_and_csum_bits() report unreadable frags
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Missing Fixes: and Cc: stable tags on a data-integrity fix.
- [Low] The new comment in skb_copy_and_csum_dev() reads: "On failure the rest of @to is zeroed; leave the checksum alone so the frame goes out…
--
net: skbuff: make skb_copy_and_csum_bits() report unreadable frags
skb_copy_and_csum_bits() now returns 0 or -EFAULT, hands the checksum back through a pointer, and is marked __must_check. On error, the callers in skb_segment(), the ICMP code, the IP append paths, sunvnet and sunrpc take the failure paths they already have. skb_copy_and_csum_dev() returns early without storing a checksum. With this change, software GSO of a devmem TCP skb fails instead of silently replacing the payload with zeroes.
Quoted 5 lines
Suggested-by Mina Almasry <[email protected]>Reviewed-by Mina Almasry <[email protected]>Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>
[Severity: Medium]
This fixes the silent payload replacement in the !sg && !csum branch of skb_segment(), but there is no Fixes: or Cc: stable tag.
The commit message says commit ab9414ed70bd ("net: skbuff: don't leave stale bytes in skb_copy_and_csum_bits()") is what made the replacement silent. That commit carries:
Could stable trees take ab9414ed70bd without this patch? Devmem TX would then send a zeroed payload under a valid TCP checksum, and the peer would accept it.
Other patches in this series carry Fixes: tags, for example "net: skbuff:
reject a negative length in skb_copy_and_csum_bits()" and "net: skbuff:
check csum_start against len in skb_copy_and_csum_dev()".
Should this one also name ab9414ed70bd (or 65249feb6b3d) in a Fixes: tag and Cc stable, so that both changes are backported together?
Quoted 4 lines
net/core/skbuff.c +0
-0
[ ... ]
Quoted 4 lines
net/core/skbuff.c +0
-0@@ -4006,9 +4025,13 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)skb_copy_from_linear_data (skb, to, csstart); csum =0 ;
net/core/skbuff.c void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to) · line 4034
Quoted 10 lines
net/core/skbuff.c +7
-3-if (csstart != skb->len) - csum =skb_copy_and_csum_bits (skb, csstart, to + csstart, - skb->len - csstart); +/* On failure the rest of @to is zeroed; leave the checksum alone so +* the frame goes out with a bad one. +*/ +if (csstart != skb->len && +skb_copy_and_csum_bits (skb, csstart, to + csstart, + skb->len - csstart, &csum)) +return ;
[Severity: Low]
Does this early return actually make the frame go out with a bad checksum?
It skips the csum_fold() store, but nothing marks the checksum as invalid. The sanity check earlier in skb_copy_and_csum_dev() only bounds csstart by skb_headlen():
if (unlikely(csstart < 0 || csstart > skb_headlen(skb) ||
(skb->ip_summed == CHECKSUM_PARTIAL &&
csstart + skb->csum_offset + sizeof(__sum16) >
skb->len))) {For CHECKSUM_PARTIAL, the field at csstart + csum_offset can therefore sit past the linear area. That puts it inside the region that skb_copy_and_csum_bits() zero-fills on failure:
if (!skb_frags_readable(skb)) {
/* Don't hand the caller a buffer with stale bytes in it. */
if (len > 0)
memset(to, 0, len);
return -EFAULT;
}For UDP over IPv4, a checksum of 0x0000 means "no checksum". Wouldn't the receiver then accept the zeroed payload?
The same applies to a CHECKSUM_NONE UDP skb sent without a checksum. The headers are copied intact, only the payload is zeroed, and nothing marks the frame as bad.
The commit message makes the same claim:
skb_copy_and_csum_dev() can't return an error, so it leaves the checksum alone and the frame goes out with a bad one.
None of the current callers (ep93xx_eth, ec_bhf, ksz884x, 8139too, sc92031, via-rhine) sets netmem_tx. validate_xmit_unreadable_skb() therefore drops unreadable skbs before they reach these drivers, and the remaining failure case needs an skb whose lengths are inconsistent.
Should the comment and the commit message be narrowed? Alternatively, this path could store a non-zero value at csstuff that is known not to match, for CHECKSUM_PARTIAL. The code is unchanged at the end of the series.
Quoted 3 lines
net/core/skbuff.c +0
-0if (skb->ip_summed ==CHECKSUM_PARTIAL ) {long csstuff = csstart + skb->csum_offset;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 2/15 net: skbuff: add skb_checksum_full() that reports failure
In reply to Josef Bacikskb_checksum() can't fail. When the range runs into unreadable frags or past the end of the skb it returns 0, which is also a valid checksum, so its callers can't tell the sum from a failure. For the receive-side validation helpers that means a packet whose payload was never checksummed can pass, and commit 20ddd0fd2fcd ("net: skbuff:
don't BUG() on leftover length in skb_checksum() and friends") made the past-the-end case one of those instead of a BUG().
Add skb_checksum_full(), which adds the range's sum to *@csump and returns 0, or returns -EFAULT for unreadable frags or a range past the end of the skb, and -EINVAL for a negative length, leaving *@csump alone. It's __must_check so a caller can't ignore the failure, and it recurses into frag_list members through itself so a failure there isn't lost either.
skb_checksum() becomes a wrapper around it that behaves as before for the callers that haven't been converted: it returns 0 on failure and warns once if that was because of unreadable frags. The following patches convert the core users, and the rest will follow per subsystem.
--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 56 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 10 deletions(-)
include/linux/skbuff.h +2 -0
@@ -4279,6 +4279,8 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len);int skb_store_bits (struct sk_buff *skb,int offset,const void *from,int len);int __must_check skb_copy_and_csum_bits (const struct sk_buff *skb,int offset,u8 *to,int len,__wsum *csum); +int __must_check skb_checksum_full (const struct sk_buff *skb,int offset, +int len,__wsum *csump);int skb_splice_bits (struct sk_buff *skb,struct sock *sk,unsigned int offset,struct pipe_inode_info *pipe,unsigned int len,unsigned int flags);
net/core/skbuff.c +46 -10
101 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 02/15] net: skbuff: add skb_checksum_full() that reports failure
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message says the skb_checksum() wrapper (net/core/skbuff.c, lines 3657-3664) "behaves as before for the…
- [Low] The new kernel-doc for skb_checksum_full() (net/core/skbuff.c, lines 3555-3557) says it returns -EFAULT if "@skb has unreadable frags…
--
net: skbuff: add skb_checksum_full() that reports failure
This adds skb_checksum_full(). It returns -EFAULT for unreadable frags or a range past the end of the skb, and -EINVAL for a negative length, instead of returning a 0 checksum. skb_checksum() becomes a wrapper around it and keeps the old return-0-on-failure behaviour for callers that have not been converted yet.
Quoted 20 lines
net/core/skbuff.c +11
-1@@ -3545,12 +3545,31 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)EXPORT_SYMBOL (skb_store_bits);/* Checksum skb data. */ -__wsum skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum) +/** +* skb_checksum_full - checksum a range of an skb +* @skb: buffer to checksum +* @offset: offset in @skb to start at +* @len: number of bytes to checksum +* @csump: the sum to add to; on success the range's sum is added to it +* +* Return: 0 on success, -EINVAL if @len is negative, or -EFAULT if @skb +* has unreadable frags in the range or runs out before @len does. On +* failure *@csump is not changed. +*/
[ ... ]
Quoted 4 lines
net/core/skbuff.c +0
-0@@ -3558,13 +3577,13 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, int len, __wsum csum) copy = len; csum =csum_partial (skb->data + offset, copy, csum);if ((len -= copy) ==0 )
net/core/skbuff.c __wsum skb_checksum(const struct sk_buff *skb, int offset, int len, __wsum csum) · line 3586
Quoted 10 lines
net/core/skbuff.c +3
-3-return csum; + goto out; offset += copy; pos = copy; } -if (WARN_ON_ONCE (!skb_frags_readable (skb))) -return 0 ; +if (!skb_frags_readable (skb)) +return -EFAULT ;
[Severity: Low]
This isn't a bug, but does the new kernel-doc match this check? The doc says -EFAULT is returned when @skb "has unreadable frags in the range". skb_frags_readable() only tests the skb-wide skb->unreadable bit, though, and this check runs before working out which frags or frag_list members the range touches.
That leads to two cases:
- On an unreadable skb, a zero-length range at offset >= skb_headlen() returns -EFAULT even though no bytes were requested.
- A range that lies entirely in readable frag_list members, past the head's own unreadable frags, is rejected without those members being visited.
The old skb_checksum() behaved the same way here. None of the callers converted later in the series seem to pass such ranges.
Should the kernel-doc describe the skb-wide check? Or should the check move so it only applies when a page frag is actually in the range?
[ ... ]
Quoted 15 lines
net/core/skbuff.c +6
-3@@ -3606,14 +3625,17 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, int len, __wsum csum) end = start + frag_iter->len;if ((copy = end - offset) >0 ) { -__wsum csum2; +__wsum csum2 =0 ; +if (copy > len) copy = len; - csum2 =skb_checksum (frag_iter, offset - start, copy, -0 ); + err =skb_checksum_full (frag_iter, offset - start, copy, + &csum2); +if (err) +return err;
[ ... ]
Quoted 1 line
net/core/skbuff.c +0
-0@@ -3621,9 +3643,23 @@ __wsum skb_checksum(const struct sk_buff *skb, int offset, int len, __wsum csum)
[ ... ]
net/core/skbuff.c __wsum skb_checksum(const struct sk_buff *skb, int offset, int len, __wsum csum) · line 3662
Quoted 9 lines
net/core/skbuff.c +9
-0+/* skb_checksum() has no way to report failure, so it returns 0, which is a +* valid checksum. Use skb_checksum_full() in new code. +*/ +__wsum skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum) +{ +if (unlikely (skb_checksum_full (skb, offset, len, &csum))) { +WARN_ON_ONCE (!skb_frags_readable (skb)); +return 0 ; + }
[Severity: Medium]
The commit message says the wrapper "behaves as before for the callers that haven't been converted: it returns 0 on failure and warns once if that was because of unreadable frags". Does that hold when the unreadable frags are in a frag_list member and not in the top-level skb?
Before this patch, the frag_list loop recursed through skb_checksum(). An unreadable member hit the WARN_ON_ONCE() and returned 0. The parent then folded that 0 in with csum_block_add() and returned the partial sum of the readable parts.
Now the member returns -EFAULT from skb_checksum_full() without a warning. The frag_list loop passes it straight up, and the wrapper only checks the outer skb:
WARN_ON_ONCE(!skb_frags_readable(skb));
If the head is readable and only a member is unreadable, the warning is lost. Unconverted callers also get 0 for the whole range instead of the old partial sum.
At this revision __skb_checksum_complete() still does:
csum = skb_checksum(skb, 0, skb->len, 0);
sum = csum_fold(csum_add(skb->csum, csum));Could this pass validation whenever the pseudo-header sum folds to 0xffff, and then set skb->csum to 0 and csum_valid to 1?
The later patch "net: skbuff: fail checksum validation when the skb can't be checksummed" converts that function. Other skb_checksum() callers stay unconverted at the end of the series and still see the changed value, for example net/netfilter/utils.c, nf_nat_proto.c, ipvs, icmp.c, ipmr.c, udp.c, mptcp and some drivers. The wrapper itself also never starts warning for nested failures.
Separately, if the top-level skb is unreadable and the failure is the new -EINVAL for a negative @len, won't this WARN_ON_ONCE() blame unreadable frags for it?
This mixed layout looks structurally possible. skb_gro_receive() links skbs onto frag_list without comparing their unreadable flags, and tcp_gro_receive() doesn't compare them either. It hasn't been shown to happen in practice.
Should the wrapper warn on nested -EFAULT as well, or should the commit message be adjusted to describe the new behaviour?
Quoted 3 lines
return csum;
}
EXPORT_SYMBOL(skb_checksum);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
Re: [PATCH net-next 02/15] net: skbuff: add skb_checksum_full() that reports failure
In reply to Josef BacikQuoted 16 lines · Josef Bacik
skb_checksum()can't fail. When the range runs into unreadable frags or past the end of the skb it returns 0, which is also a valid checksum, so its callers can't tell the sum from a failure. For the receive-side validation helpers that means a packet whose payload was never checksummed can pass, and commit20ddd0fd2fcd("net: skbuff:
don'tBUG()on leftover length inskb_checksum()and friends") made the past-the-end case one of those instead of aBUG().Add
skb_checksum_full(), which adds the range's sum to *@csump and returns 0, or returns-EFAULTfor unreadable frags or a range past the end of the skb, and-EINVALfor a negative length, leaving *@csump alone. It's__must_checkso a caller can't ignore the failure, and it recurses intofrag_listmembers through itself so a failure there isn't lost either.
Quoted 5 lines
skb_checksum()becomes a wrapper around it that behaves as before for the callers that haven't been converted: it returns 0 on failure and warns once if that was because of unreadable frags. The following patches convert the core users, and the rest will follow per subsystem.
Is it possible to stop sending 1 large series where some patches are related and some patches are not? Are the changes for segmentation in this series related to checksumming?
Quoted 37 lines
Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 56 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 10 deletions(-)include/linux/skbuff.h +2
-0@@ -4279,6 +4279,8 @@ int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len);int skb_store_bits (struct sk_buff *skb,int offset,const void *from,int len);int __must_check skb_copy_and_csum_bits (const struct sk_buff *skb,int offset,u8 *to,int len,__wsum *csum); +int __must_check skb_checksum_full (const struct sk_buff *skb,int offset, +int len,__wsum *csump);int skb_splice_bits (struct sk_buff *skb,struct sock *sk,unsigned int offset,struct pipe_inode_info *pipe,unsigned int len,unsigned int flags);net/core/skbuff.c +8
-1@@ -3545,12 +3545,31 @@ int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)EXPORT_SYMBOL (skb_store_bits);/* Checksum skb data. */ -__wsum skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum) +/** +* skb_checksum_full - checksum a range of an skb +* @skb: buffer to checksum +* @offset: offset in @skb to start at +* @len: number of bytes to checksum +* @csump: the sum to add to; on success the range's sum is added to it +* +* Return: 0 on success, -EINVAL if @len is negative, or -EFAULT if @skb
net/core/skbuff.c int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len) · line 3565
Quoted 10 lines
net/core/skbuff.c +6
-0+* has unreadable frags in the range or runs out before @len does. On +* failure *@csump is not changed. +*/ +int skb_checksum_full (const struct sk_buff *skb,int offset,int len, +__wsum *csump) {int start =skb_headlen (skb);int i, copy = start - offset;struct sk_buff *frag_iter; +__wsum csum = *csump;
Check for reverse christmas tree.
net/core/skbuff.c int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len) · line 3572
Quoted 7 lines
net/core/skbuff.c +6
-0int pos =0 ; +int err; + +if (unlikely (len <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }
We don't normally go for these defensive checks.
Signature · 2 lines
Thanks, Mina
PATCH 3/15 net: skbuff: fail checksum validation when the skb can't be checksummed
In reply to Josef Bacik__skb_checksum_complete() verifies a received packet with skb_checksum(), which returns 0 when the range runs into unreadable frags or past the end of the skb. 0 is a valid sum, so it's treated as
one: it adds skb->csum, the pseudo-header sum, and folds the result. With a sum of 0 that's csum_fold(skb->csum), which is 0 whenever the pseudo-header sum folds to 0xffff, so a packet whose payload was never checksummed is accepted, marked csum_valid, and left with a wrong CHECKSUM_COMPLETE value in skb->csum.
__skb_checksum_complete_head() passes skb->csum in as the seed, so a failure there folds 0 and the packet fails validation, but only because skb_checksum() happened to drop the seed.
Use skb_checksum_full() in both, and report a packet that can't be checksummed as having a bad checksum, so callers drop it the way they drop any other bad checksum. Clear csum_valid, and leave skb->csum and ip_summed alone, since there's no full packet checksum to store.
Found by the Sashiko AI review of the series that made skb_checksum() return 0 for a range past the end of the skb.
--- net/core/skbuff.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
net/core/skbuff.c +18 -3
@@ -3860,9 +3860,17 @@ EXPORT_SYMBOL(skb_crc32c);__sum16 __skb_checksum_complete_head (struct sk_buff *skb,int len) { +__wsum csum = skb->csum;__sum16 sum; - sum =csum_fold (skb_checksum (skb,0 , len, skb->csum)); +/* If the data can't be checksummed it can't be valid either. */ +if (skb_checksum_full (skb,0 , len, &csum)) { +if (!skb_shared (skb)) + skb->csum_valid =0 ; +return (__force __sum16 )1 ; + } + + sum =csum_fold (csum);/* See comments in __skb_checksum_complete(). */ if (likely (!sum)) { if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE) &&
@@ -3886,10 +3894,17 @@ EXPORT_SYMBOL(__skb_checksum_complete_head);*/ __sum16 __skb_checksum_complete (struct sk_buff *skb) { -__wsum csum; +__wsum csum =0 ;__sum16 sum; - csum =skb_checksum (skb,0 , skb->len,0 ); +/* If the data can't be checksummed it can't be valid either. Leave +* skb->csum alone, it's not a full packet checksum. +*/ +if (skb_checksum_full (skb,0 , skb->len, &csum)) { +if (!skb_shared (skb)) + skb->csum_valid =0 ; +return (__force __sum16 )1 ; + } sum =csum_fold (csum_add (skb->csum, csum));/* This check is inverted, because we already knew the hardware
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 03/15] net: skbuff: fail checksum validation when the skb can't be checksummed
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The fix does not hold when conntrack checks checksums first.
- [High] __skb_gro_checksum_complete() (net/core/gro.c:794-813) has the same false-accept defect this commit fixes in…
- [Medium] The Fixes: tag is incomplete for stable backporting.
- [Low] The block comment above __skb_checksum_complete() (net/core/skbuff.c:3891-3893) still says 'The new checksum is stored…
--
net: skbuff: fail checksum validation when the skb can't be checksummed
This commit switches __skb_checksum_complete() and __skb_checksum_complete_head() to skb_checksum_full(). When the skb data can't be checksummed, they now report a bad checksum. On that failure path csum_valid is cleared, and skb->csum and ip_summed are left alone.
Quoted 1 line
Fixes 20ddd0fd2fcd ("net: skbuff: don't BUG() on leftover length in skb_checksum() and friends")
[Severity: Medium]
Is this Fixes: tag complete for stable backports?
The likely remote trigger for __skb_checksum_complete() is unreadable devmem frags. skb_checksum() has returned 0 for those since 65249feb6b3d ("net: add support for skbs with unreadable frags"):
if (WARN_ON_ONCE(!skb_frags_readable(skb)))
return 0;The 20ddd0fd2fcd commit message also says skb_checksum() returns 0 "as they already do for unreadable frags".
__skb_checksum_complete() checksums from offset 0 to skb->len. It can only run past the end if the skb lengths are inconsistent.
With only Fixes: 20ddd0fd2fcd, stable trees from 6.12 onward that have 65249feb6b3d but not 20ddd0fd2fcd would not pick this up. Should 65249feb6b3d be listed as well?
This patch also depends on the previous patch in the series ("net:
skbuff: add skb_checksum_full() that reports failure"). Nothing in the tags records that dependency.
Quoted 4 lines
net/core/skbuff.c +0
-0
[ ... ]
net/core/skbuff.c EXPORT_SYMBOL(__skb_checksum_complete_head); · line 3902
Quoted 12 lines
net/core/skbuff.c +4
-2@@ -3886,10 +3894,17 @@ EXPORT_SYMBOL(__skb_checksum_complete_head);*/ __sum16 __skb_checksum_complete (struct sk_buff *skb) { -__wsum csum; +__wsum csum =0 ;__sum16 sum; - csum =skb_checksum (skb,0 , skb->len,0 ); +/* If the data can't be checksummed it can't be valid either. Leave +* skb->csum alone, it's not a full packet checksum. +*/
[Severity: Low]
The block comment above __skb_checksum_complete() still says:
* zero. The new checksum is stored back into skb->csum unless the skb is
* shared.
On the new failure path, skb->csum is not stored back even for unshared skbs. That contradicts the new inline comment. skb_remcsum_process() ignores the return value of __skb_checksum_complete() and then uses skb->csum, so it relies on this post-condition.
The return-value comments for __skb_checksum_validate_complete() and __skb_checksum_validate() in include/linux/skbuff.h also say:
* non-zero: value of invalid checksum
The new path returns the constant (__force __sum16)1 rather than a computed value. Should both comments be updated?
net/core/skbuff.c EXPORT_SYMBOL(__skb_checksum_complete_head); · line 3907
Quoted 5 lines
net/core/skbuff.c +5
-0+if (skb_checksum_full (skb,0 , skb->len, &csum)) { +if (!skb_shared (skb)) + skb->csum_valid =0 ; +return (__force __sum16 )1 ; + }
[Severity: High]
Can leaving ip_summed set to CHECKSUM_COMPLETE here let a later validator accept the packet anyway?
Callers have already replaced skb->csum with the pseudo-header sum before calling this function. nf_ip_checksum() does this when the hardware CHECKSUM_COMPLETE sum fails to validate:
net/netfilter/utils.c:nf_ip_checksum() {
...
case CHECKSUM_NONE:
...
skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
skb->len - dataoff,
protocol, 0);
csum = __skb_checksum_complete(skb);
...
}For an skb with unreadable frags, skb_checksum_full() fails. The skb then leaves this function with ip_summed == CHECKSUM_COMPLETE and skb->csum == psum.
Conntrack does not drop on a bad checksum:
nf_conntrack_in()
nf_conntrack_tcp_packet()
tcp_error() -> true
return -NF_ACCEPT ret = -ret; -> NF_ACCEPT
The packet then reaches tcp_v4_rcv()->skb_checksum_init()->__skb_checksum_validate_complete():
if (skb->ip_summed == CHECKSUM_COMPLETE) {
if (!csum_fold(csum_add(psum, skb->csum))) {
skb->csum_valid = 1;
return 0;inet_compute_pseudo() produces the same psum, so this computes csum_fold(psum + psum). That is 0 exactly when psum folds to 0xffff, which is the condition the commit message says it closes. The sender controls it through the packet length or source address. Conntrack checksumming is on by default (nf_conntrack_checksum = 1).
The commit message says:
report a packet that can't be checksummed as having a bad checksum, so callers drop it the way they drop any other bad checksum.
This caller doesn't drop it. Would it make sense to move ip_summed off CHECKSUM_COMPLETE (for example to CHECKSUM_NONE) on this path when the skb is not shared? That way later validators can't trust the stale pseudo-header sum. The series leaves this code as it is.
net/core/skbuff.c EXPORT_SYMBOL(__skb_checksum_complete_head); · line 3910
Quoted 3 lines
net/core/skbuff.c +0
-0sum =csum_fold (csum_add (skb->csum, csum));/* This check is inverted, because we already knew the hardware
[Severity: High]
Should __skb_gro_checksum_complete() in net/core/gro.c be converted too? It has the same false-accept pattern, its comment points to the comments in __skb_checksum_complete(), and the series doesn't change it:
net/core/gro.c:__skb_gro_checksum_complete() {
...
wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb), 0);
/* NAPI_GRO_CB(skb)->csum holds pseudo checksum */
sum = csum_fold(csum_add(NAPI_GRO_CB(skb)->csum, wsum));
...
NAPI_GRO_CB(skb)->csum = wsum;
NAPI_GRO_CB(skb)->csum_valid = 1;
...
}For a devmem skb with unreadable frags, skb_checksum() fires WARN_ON_ONCE(!skb_frags_readable(skb)) and returns 0. sum is then csum_fold(psum), which is 0 when psum folds to 0xffff.
The path is:
tcp4_gro_receive()
skb_gro_checksum_validate()
__skb_gro_checksum_validate_complete()
__skb_gro_checksum_complete()
skb_gro_incr_csum_unnecessary()
For CHECKSUM_NONE skbs this ends in CHECKSUM_UNNECESSARY. For merged CHECKSUM_COMPLETE skbs, tcp_gro_complete() sets CHECKSUM_PARTIAL. In both cases TCP never validates the payload again, and GRO accepts the packet before the helpers changed here ever run.
Every bad-checksum packet on such a queue also hits the WARN_ON_ONCE() from softirq context, which a remote sender can trigger. The WARN itself comes from 65249feb6b3d.
The previous patch, "net: skbuff: add skb_checksum_full() that reports failure", says the following patches convert the core users. This net/core user isn't converted anywhere in the series.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
Re: [PATCH net-next 03/15] net: skbuff: fail checksum validation when the skb can't be checksummed
Quoted 12 lines · On Thu, Oct 22, 2026 at 9:52 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
Quoted 3 lines
- [High] The fix does not hold when conntrack checks checksums first.
- [High]__skb_gro_checksum_complete()(net/core/gro.c:794-813) has the same false-accept defect this commit fixes in…
Both high's here seem like legitimate issue, al though the latter is maybe pre-existing.
Signature · 2 lines
Thanks, Mina
Re: [PATCH net-next 03/15] net: skbuff: fail checksum validation when the skb can't be checksummed
In reply to Josef BacikQuoted 60 lines · Josef Bacik
__skb_checksum_complete()verifies a received packet withskb_checksum(), which returns 0 when the range runs into unreadable frags or past the end of the skb. 0 is a valid sum, so it's treated as
one: it addsskb->csum, the pseudo-header sum, and folds the result. With a sum of 0 that'scsum_fold(skb->csum), which is 0 whenever the pseudo-header sum folds to0xffff, so a packet whose payload was never checksummed is accepted, markedcsum_valid, and left with a wrongCHECKSUM_COMPLETEvalue inskb->csum.
__skb_checksum_complete_head()passesskb->csumin as the seed, so a failure there folds 0 and the packet fails validation, but only becauseskb_checksum()happened to drop the seed.Use
skb_checksum_full()in both, and report a packet that can't be checksummed as having a bad checksum, so callers drop it the way they drop any other bad checksum. Clearcsum_valid, and leaveskb->csumandip_summedalone, since there's no full packet checksum to store.Found by the Sashiko AI review of the series that made
skb_checksum()return 0 for a range past the end of the skb.Fixes 20ddd0fd2fcd ("net: skbuff: don't BUG() on leftover length in skb_checksum() and friends")Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- net/core/skbuff.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)net/core/skbuff.c +10
-2@@ -3860,9 +3860,17 @@ EXPORT_SYMBOL(skb_crc32c);__sum16 __skb_checksum_complete_head (struct sk_buff *skb,int len) { +__wsum csum = skb->csum;__sum16 sum; - sum =csum_fold (skb_checksum (skb,0 , len, skb->csum)); +/* If the data can't be checksummed it can't be valid either. */ +if (skb_checksum_full (skb,0 , len, &csum)) { +if (!skb_shared (skb)) + skb->csum_valid =0 ; +return (__force __sum16 )1 ; + } + + sum =csum_fold (csum);/* See comments in __skb_checksum_complete(). */ if (likely (!sum)) { if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE) &&@@ -3886,10 +3894,17 @@ EXPORT_SYMBOL(__skb_checksum_complete_head);*/ __sum16 __skb_checksum_complete (struct sk_buff *skb) { -__wsum csum; +__wsum csum =0 ;__sum16 sum;
net/core/skbuff.c EXPORT_SYMBOL(__skb_checksum_complete_head); · line 3907
Quoted 10 lines
net/core/skbuff.c +8
-1- csum =skb_checksum (skb,0 , skb->len,0 ); +/* If the data can't be checksummed it can't be valid either. Leave +* skb->csum alone, it's not a full packet checksum. +*/ +if (skb_checksum_full (skb,0 , skb->len, &csum)) { +if (!skb_shared (skb)) + skb->csum_valid =0 ; +return (__force __sum16 )1 ; + }
I think maybe we need to be careful here which are all the skb flags that we need to touch to indicate that the checksum failed.
My LLM is recommending:
if (!skb_shared(skb)) {
skb->ip_summed = CHECKSUM_NONE;
skb->csum_complete_sw = 0;
skb->csum_valid = 0;
}Seems ip_summed = *_NONE was caught elsewhere, but also maybe csum_complete_sw=0 makes sense.
Signature · 2 lines
Thanks, Mina
PATCH 4/15 net: skbuff: fail segmentation when a segment can't be checksummed
In reply to Josef BacikWhen the device can't checksum the protocol, skb_segment() computes each segment's checksum in software with skb_checksum(). With SG on, the segments share the original frags, and a devmem TCP skb keeps its whole payload in unreadable frags. The devmem MSG_ZEROCOPY path never sets SKBFL_SHARED_FRAG, so the __skb_linearize() fallback is skipped too. skb_checksum() then warns and returns 0, and tcp_gso_segment() writes a TCP checksum that doesn't cover the payload that goes out.
That's reachable with tx-checksumming off and SG on: sk_setup_caps() still gives TCP SG and HW_CSUM, so the dmabuf send is accepted, and harmonize_features() strips the checksum features but keeps SG.
Use skb_checksum_full() and fail the segmentation with -EFAULT when it can't checksum a segment, as skb_segment() already does when it can't copy one.
Found by the Sashiko AI review of an earlier fix for the same path with SG off.
--- net/core/skbuff.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/core/skbuff.c +7 -3
@@ -5239,9 +5239,13 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,if (!nskb->remcsum_offload) nskb->ip_summed =CHECKSUM_NONE ; -SKB_GSO_CB (nskb)->csum = -skb_checksum (nskb, doffset, - nskb->len - doffset,0 ); +SKB_GSO_CB (nskb)->csum =0 ; +if (skb_checksum_full (nskb, doffset, + nskb->len - doffset, + &SKB_GSO_CB (nskb)->csum)) { + err = -EFAULT ; + goto err; + }SKB_GSO_CB (nskb)->csum_start =skb_headroom (nskb) + doffset; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 04/15] net: skbuff: fail segmentation when a segment can't be checksummed
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit fixes a real, user-visible TX bug but has no Fixes:
tag (and no Cc: stable).
--
net: skbuff: fail segmentation when a segment can't be checksummed
This patch changes the sg && !csum software checksum path in skb_segment() to use skb_checksum_full(). The segmentation now fails with -EFAULT when a segment can't be checksummed. This covers devmem TCP skbs whose payload is in unreadable frags: skb_checksum() used to warn and return 0, so the TCP checksum didn't cover the payload.
Quoted 6 lines
Found by the Sashiko AI review of an earlier fix for the same path with SG off.
[Severity: Low]
Should this have a Fixes: tag, and possibly Cc: stable?
Before this patch, the perform_csum_check branch of skb_segment() called skb_checksum() on segments that share the devmem skb's net_iov frags. zerocopy_fill_skb_from_devmem() in net/core/datagram.c never sets SKBFL_SHARED_FRAG, so the __skb_linearize() fallback is skipped and __skb_checksum() ends up here:
if (WARN_ON_ONCE(!skb_frags_readable(skb)))
return 0;That WARN is fatal with panic_on_warn. tcp_gso_segment() then writes a TCP checksum that doesn't cover the payload that goes out.
This path became reachable when unreadable-frag TX skbs were added by:
bd61848900bf ("net: devmem: Implement TX path")
That looks like the right Fixes: target. Another patch in this series, "net: skbuff: fail checksum validation when the skb can't be checksummed", does carry a Fixes: tag. Without one here, the stable tooling won't pick up this fix.
This patch also calls skb_checksum_full(), which is added by the earlier patch in this series, "net: skbuff: add skb_checksum_full() that reports failure". Could the commit message mention that dependency, so a backport takes both patches?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
Re: [PATCH net-next 04/15] net: skbuff: fail segmentation when a segment can't be checksummed
In reply to Josef BacikQuoted 32 lines · Josef Bacik
When the device can't checksum the protocol,
skb_segment()computes each segment's checksum in software withskb_checksum(). With SG on, the segments share the original frags, and a devmem TCP skb keeps its whole payload in unreadable frags. The devmemMSG_ZEROCOPYpath never setsSKBFL_SHARED_FRAG, so the__skb_linearize()fallback is skipped too.skb_checksum()then warns and returns 0, andtcp_gso_segment()writes a TCP checksum that doesn't cover the payload that goes out.That's reachable with tx-checksumming off and SG on:
sk_setup_caps()still gives TCP SG andHW_CSUM, so the dmabuf send is accepted, andharmonize_features()strips the checksum features but keeps SG.Use
skb_checksum_full()and fail the segmentation with-EFAULTwhen it can't checksum a segment, asskb_segment()already does when it can't copy one.Found by the Sashiko AI review of an earlier fix for the same path with SG off.
Link https://lore.kernel.org/all/20261009-b4-skb-segment-nosg-unreadable-v1-1-7e2334a55fe8@toxicpanda.com/ open hereAssisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- net/core/skbuff.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)net/core/skbuff.c +0
-0
net/core/skbuff.c struct sk_buff *skb_segment(struct sk_buff *head_skb, · line 5242
Quoted 7 lines
net/core/skbuff.c +1
-3@@ -5239,9 +5239,13 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,if (!nskb->remcsum_offload) nskb->ip_summed =CHECKSUM_NONE ; -SKB_GSO_CB (nskb)->csum = -skb_checksum (nskb, doffset, - nskb->len - doffset,0 ); +SKB_GSO_CB (nskb)->csum =0 ;
So I wonder if this needs to be a generic thing to do insidk of skb_checksum_full. It seems like the previous patch is complaining some fields in the skb are no-longer set correctly if we fail checksumming, like ip_summ. Maybe ->csum as well should not be left set to non-zero if skb_checksum_full fails.
Anyway,
Signature · 2 lines
Thanks, Mina
PATCH 5/15 net: skbuff: fail pskb_trim_rcsum() when it can't checksum the tail
In reply to Josef BacikFor a CHECKSUM_COMPLETE skb, pskb_trim_rcsum() subtracts the checksum of the bytes it trims from skb->csum. It gets that checksum from skb_checksum(), so if the trimmed range runs into unreadable frags in a frag_list member, or past the end of the skb, it subtracts 0 and leaves skb->csum covering bytes that are no longer in the packet.
pskb_trim_rcsum() can already fail, and its callers drop the packet when it does. Use skb_checksum_full() and return its error.
--- net/core/skbuff.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/core/skbuff.c +7 -3
@@ -2829,9 +2829,13 @@ 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); +__wsum csum =0 ; +int err; + + err =skb_checksum_full (skb, len, delta, &csum); +if (err) +return err; + skb->csum =csum_block_sub (skb->csum, csum, len);return 0 ; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 05/15] net: skbuff: fail pskb_trim_rcsum() when it can't checksum the tail
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit fixes a real CHECKSUM_COMPLETE corruption in pskb_trim_rcsum_complete() (net/core/skbuff.c) but has no Fixes: tag,…
- [Low] In pskb_trim_rcsum_complete() (net/core/skbuff.c), the readable- head branch now returns skb_checksum_full()'s -EFAULT unconditionally.
--
net: skbuff: fail pskb_trim_rcsum() when it can't checksum the tail
This patch changes pskb_trim_rcsum_complete() to use skb_checksum_full() instead of skb_checksum(). If the checksum of the trimmed tail can't be computed, the error is now returned and callers drop the packet. Before this, 0 was subtracted from skb->csum.
Quoted 2 lines
pskb_trim_rcsum()can already fail, and its callers drop the packet when it does. Useskb_checksum_full()and return its error.
[Severity: Low]
This isn't a bug, but should this commit carry a Fixes: tag?
Before this patch, the readable-head branch of pskb_trim_rcsum_complete() only checked the top-level skb->unreadable bit. If the trimmed tail reached an unreadable frag_list member, skb->csum was left covering the trimmed bytes.
That layout looks reachable. inet_frag_reasm_finish() keeps CHECKSUM_COMPLETE, and it links fragments onto frag_list when skb_try_coalesce() refuses them:
net/core/skbuff.c:skb_try_coalesce() {
...
if (skb_frags_readable(from) != skb_frags_readable(to))
return false;
...
}The gap seems to go back to 65249feb6b3d ("net: add support for skbs with unreadable frags"). 2e357f002c61 ("net: Avoid checksumming unreadable skb tail on trim") only covered the top-level case.
The commit message also mentions the "past the end of the skb" case. That case was a BUG() until 20ddd0fd2fcd turned it into a silent 0.
Two sibling patches in this series fix the same consequence of 20ddd0fd2fcd, and both carry Fixes: 20ddd0fd2fcd:
"net: skbuff: fail checksum validation when the skb can't be checksummed" "net: skbuff: add skb_crc32c_full() that reports failure"
The commit message also doesn't say that this patch depends on the earlier "net: skbuff: add skb_checksum_full() that reports failure" patch. Could that dependency be noted for anyone backporting this?
Quoted 7 lines
net/core/skbuff.c +0
-0@@ -2829,9 +2829,13 @@ static int pskb_trim_rcsum_complete(struct sk_buff *skb, unsigned int len)int delta = skb->len - len;
net/core/skbuff.c static int pskb_trim_rcsum_complete(struct sk_buff *skb, unsigned int len) · line 2837
Quoted 10 lines
net/core/skbuff.c +6
-3if (skb_frags_readable (skb)) { - skb->csum =csum_block_sub (skb->csum, -skb_checksum (skb, len, delta,0 ), - len); +__wsum csum =0 ; +int err; + + err =skb_checksum_full (skb, len, delta, &csum); +if (err) +return err;
[Severity: Low]
Should this fall back to CHECKSUM_NONE when only the trimmed bytes are unreadable?
Take a head with skb->unreadable clear, where the tail [len, skb->len) lies entirely in an unreadable frag_list member. skb_checksum_full() recurses into that member and returns -EFAULT, and the packet is dropped.
pskb_trim_rcsum_complete() already handles the case where the trimmed bytes are unreadable but the rest can be checksummed. It only does so when the top-level bit is set:
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;
So the same data layout is either kept or dropped, depending on whether the unreadable flag is on the head or on a frag_list member.
One way to get there is IP reassembly on a devmem/zcrx queue. If a readable first fragment is followed by an unreadable one, inet_frag_reasm_finish() produces a readable CHECKSUM_COMPLETE head with an unreadable frag_list member. When the UDP length is shorter than the datagram, the call chain is:
__udp4_lib_rcv()
pskb_trim_rcsum(skb, ulen)
pskb_trim_rcsum_slow()
pskb_trim_rcsum_complete()
skb_checksum_full() -> -EFAULTUDP then drops the packet through short_packet.
___pskb_trim() would have dropped that member and cleared the unreadable bit:
if (!skb_shinfo(skb)->nr_frags && !skb_has_frag_list(skb)) skb->unreadable = 0;
That would leave the trimmed skb fully readable, so software could checksum it.
Before this patch the packet was accepted. __skb_checksum_complete() recomputed the checksum over the trimmed skb and reported netdev_rx_csum_fault().
Would falling back to CHECKSUM_NONE when [0, len) is readable avoid both the drop and the old splat?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 6/15 net: skbuff: add skb_crc32c_full() that reports failure
In reply to Josef Bacikskb_crc32c() has the same problem as skb_checksum(): when the range runs into unreadable frags or past the end of the skb it returns 0, which is also a valid CRC. sctp_compute_cksum() complements it, so a failed walk looks like a checksum of 0xffffffff whatever the packet contains, and the packet is accepted whenever its checksum field holds that.
Add skb_crc32c_full(), which updates *@crcp and returns 0, or returns -EFAULT or -EINVAL and leaves *@crcp alone, like skb_checksum_full(). skb_crc32c() becomes a wrapper that behaves as before for the callers that haven't been converted.
Convert skb_crc32c_csum_help(), which already returns an error when it can't fill in the CRC, so a transmitted SCTP packet that can't be checksummed is dropped instead of going out with a CRC of 0xffffffff. The SCTP and other callers will follow with the skb_checksum() callers.
--- include/linux/skbuff.h | 2 ++ net/core/dev.c | 7 +++++-- net/core/skbuff.c | 51 ++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 10 deletions(-)
include/linux/skbuff.h +2 -0
@@ -4329,6 +4329,8 @@ static inline int memcpy_to_msg(struct msghdr *msg, void *data, int len)__wsum skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum); +int __must_check skb_crc32c_full (const struct sk_buff *skb,int offset, +int len,u32 *crcp);u32 skb_crc32c (const struct sk_buff *skb,int offset,int len,u32 crc); static inline void * __must_check
net/core/dev.c +5 -2
@@ -3738,8 +3738,11 @@ int skb_crc32c_csum_help(struct sk_buff *skb)if (ret) goto out; - crc = ~skb_crc32c (skb, start, skb->len - start, ~0 ); - *(__le32 *)(skb->data + offset) =cpu_to_le32 (crc); + crc = ~0 ; + ret =skb_crc32c_full (skb, start, skb->len - start, &crc); +if (ret) + goto out; + *(__le32 *)(skb->data + offset) =cpu_to_le32 (~crc);skb_reset_csum_not_inet (skb); out:return ret;
net/core/skbuff.c +43 -8
92 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 06/15] net: skbuff: add skb_crc32c_full() that reports failure
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new kernel-doc for skb_crc32c_full() (net/core/skbuff.c, above line 3810) says it returns -EFAULT when "@skb has unreadable…
- [Low] The commit message says skb_crc32c() 'becomes a wrapper that behaves as before', but its unreadable-frags WARN now covers less.
--
net: skbuff: add skb_crc32c_full() that reports failure
This commit adds skb_crc32c_full(). When the walk runs into unreadable frags or past the end of the skb, it returns an error instead of a CRC of 0. skb_crc32c() becomes a wrapper around it, and skb_crc32c_csum_help() is converted, so SCTP packets that can't be checksummed are dropped instead of being sent with a bogus CRC.
Quoted 22 lines
net/core/skbuff.c +12
-1@@ -3788,23 +3788,41 @@ int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,EXPORT_SYMBOL (skb_copy_and_csum_bits);#ifdef CONFIG_NET_CRC32C -u32 skb_crc32c (const struct sk_buff *skb,int offset,int len,u32 crc) +/** +* skb_crc32c_full - CRC32C a range of an skb +* @skb: buffer to read +* @offset: offset in @skb to start at +* @len: number of bytes to include +* @crcp: the CRC to continue from; on success, updated with the range +* +* Return: 0 on success, -EINVAL if @len is negative, or -EFAULT if @skb +* has unreadable frags in the range or runs out before @len does. On +* failure *@crcp is not changed. +*/ +int skb_crc32c_full (const struct sk_buff *skb,int offset,int len,u32 *crcp) {
[ ... ]
Quoted 4 lines
net/core/skbuff.c +0
-0if (copy >0 ) { copy =min (copy, len); crc =crc32c (crc, skb->data + offset, copy); len -= copy;
net/core/skbuff.c int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, · line 3825
Quoted 10 lines
net/core/skbuff.c +3
-3if (len ==0 ) -return crc; + goto out; offset += copy; } -if (WARN_ON_ONCE (!skb_frags_readable (skb))) -return 0 ; +if (!skb_frags_readable (skb)) +return -EFAULT ;
[Severity: Low]
The kernel-doc above says -EFAULT means "@skb has unreadable frags in the range". Does this check actually look at the range?
skb_frags_readable() only tests the flag for the whole skb:
include/linux/skbuff.h:skb_frags_readable() {
return !skb->unreadable;
}Take len == 0 with offset >= skb_headlen(skb). A readable skb walks zero bytes and returns 0, but an unreadable skb returns -EFAULT here.
Now take a range that lies entirely in readable frag_list children of an skb whose own frags are unreadable. That also fails here, before the frag_list loop runs.
No current caller seems to hit this. skb_crc32c_csum_help() always starts inside the linear head and passes a positive len.
Could the kernel-doc be reworded? Alternatively, this check could apply only when the remaining range reaches frags[]. skb_checksum_full(), added earlier in the series, has the same mismatch.
[ ... ]
Quoted 9 lines
net/core/skbuff.c +4
-1@@ -3844,19 +3862,36 @@ u32 skb_crc32c(const struct sk_buff *skb, int offset, int len, u32 crc) copy = end - offset;if (copy >0 ) { copy =min (copy, len); - crc =skb_crc32c (frag_iter, offset - start, copy, crc); + err =skb_crc32c_full (frag_iter, offset - start, copy, + &crc); +if (err) +return err;
[ ... ]
net/core/skbuff.c u32 skb_crc32c(const struct sk_buff *skb, int offset, int len, u32 crc) · line 3892
Quoted 7 lines
net/core/skbuff.c +7
-0+/* skb_crc32c() has no way to report failure, so it returns 0, which is a +* valid CRC. Use skb_crc32c_full() in new code. +*/ +u32 skb_crc32c (const struct sk_buff *skb,int offset,int len,u32 crc) +{ +if (unlikely (skb_crc32c_full (skb, offset, len, &crc))) { +WARN_ON_ONCE (!skb_frags_readable (skb));
[Severity: Low]
The commit message says skb_crc32c() "becomes a wrapper that behaves as before". Does the unreadable-frags warning still fire for frag_list children?
Before this patch, the frag_list loop recursed through skb_crc32c(frag_iter, ...). An unreadable child therefore hit WARN_ON_ONCE(!skb_frags_readable(skb)) at the child level.
Now the recursion goes through skb_crc32c_full(frag_iter, ...). The child returns -EFAULT without a warning, and this WARN_ON_ONCE() only tests the outer skb.
So a readable parent with an unreadable frag_list child now returns 0 to sctp_compute_cksum(), siw_crc_skb() or batadv_bla_check_duplist() without warning. Before the patch it warned once.
The return value is 0 either way, so only the diagnostic changes. skb_gro_receive() doesn't seem to check readability when it merges into frag_list, so this layout looks possible, but that hasn't been confirmed end to end.
The skb_checksum() wrapper from earlier in the series has the same pattern.
Quoted 5 lines
net/core/skbuff.c +2
-0+return 0 ; + }return crc; }EXPORT_SYMBOL (skb_crc32c);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 7/15 net: skbuff: let skb_zerocopy() copy a short skb without head_frag
In reply to Josef BacikCommit 433380f5ab8f ("net: skbuff: don't BUG() on a missing head_frag in skb_zerocopy()") turned the BUG_ON(!from->head_frag && !hlen) into an -EFAULT return, but left it ahead of the small-payload path. That path copies everything with skb_copy_bits() and never references the head as a page, so the check doesn't apply to it.
Open vSwitch gets there with an ordinary request. OVS_PACKET_CMD_EXECUTE allocates the packet with __dev_alloc_skb(..., GFP_KERNEL), which gives it a kmalloc'd head without head_frag. A POP_ETH action on a 14 byte frame leaves it empty, and a USERSPACE action then queues it with queue_userspace_packet(), which calls skb_zerocopy(user_skb, skb, 0, 0). That used to BUG(), and now the upcall fails and the packet is counted as lost, with a WARN on CONFIG_DEBUG_NET kernels. OVS_PACKET_CMD_EXECUTE only needs CAP_NET_ADMIN in the user namespace that owns the network namespace, so with the openvswitch module loaded any user can do this from their own namespace.
Move the check below the small-payload path, so a zero-length copy succeeds the same way it does for an skb with a head_frag, and document the -EFAULT case.
Found by the Sashiko AI review of v2 of the series that made the change.
--- net/core/skbuff.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/core/skbuff.c +10 -6
@@ -4014,8 +4014,9 @@ EXPORT_SYMBOL_GPL(skb_zerocopy_headlen);* Return value: * 0: everything is OK * -ENOMEM: couldn't orphan frags of @from due to lack of memory -* -EFAULT: skb_copy_bits() found some problem with skb geometry, or readable head -* payload would be mixed with unreadable frags. +* -EFAULT: skb_copy_bits() found some problem with skb geometry, @from has +* no head_frag and @hlen is 0 while @len doesn't fit in @to's tailroom, +* or readable head payload would be mixed with unreadable frags. */ int skb_zerocopy (struct sk_buff *to,struct sk_buff *from,int len,int hlen)
@@ -4026,15 +4027,18 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)struct page *page;unsigned int offset; +/* dont bother with small payloads */ +if (len <=skb_tailroom (to)) +return skb_copy_bits (from,0 ,skb_put (to, len), len); + +/* Without a head_frag the head can't be referenced as a page, so the +* caller has to ask for it to be copied. +*/ if (unlikely (!from->head_frag && !hlen)) {DEBUG_NET_WARN_ON_ONCE (1 );return -EFAULT ; } -/* dont bother with small payloads */ -if (len <=skb_tailroom (to)) -return skb_copy_bits (from,0 ,skb_put (to, len), len); -if (hlen) { ret =skb_copy_bits (from,0 ,skb_put (to, hlen), hlen);if (unlikely (ret))
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 07/15] net: skbuff: let skb_zerocopy() copy a short skb without head_frag
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The Fixes: tag points at the wrong commit, so stable kernels will not get this fix even though they still have a BUG() that an…
--
net: skbuff: let skb_zerocopy() copy a short skb without head_frag
This patch moves the !from->head_frag && !hlen check in skb_zerocopy() below the small-payload skb_copy_bits() path. A short copy from an skb without a head_frag, including a zero-length one, now succeeds. The motivating case is an Open vSwitch OVS_PACKET_CMD_EXECUTE request doing POP_ETH followed by USERSPACE, which ends up calling skb_zerocopy(user_skb, skb, 0, 0).
Quoted 6 lines
That used to
BUG(), and now the
upcall fails and the packet is counted as lost, with a WARN onCONFIG_DEBUG_NETkernels.OVS_PACKET_CMD_EXECUTEonly needsCAP_NET_ADMINin the user namespace that owns the network namespace, so with the openvswitch module loaded any user can do this from their own namespace.
[ ... ]
Quoted 1 line
Fixes 433380f5ab8f ("net: skbuff: don't BUG() on a missing head_frag in skb_zerocopy()")
[Severity: Medium]
Is this the right commit for the Fixes: tag?
433380f5ab8f only turned the existing BUG_ON() into an -EFAULT return. It went in through net-next as part of the "net: skbuff: replace most BUG_ON()s with error returns" series, with no Fixes: or Cc: stable tag, so no stable tree has it.
The ordering problem is older than that. Before 433380f5ab8f, skb_zerocopy() looked like this:
BUG_ON(!from->head_frag && !hlen);
/* dont bother with small payloads */
if (len <= skb_tailroom(to))
return skb_copy_bits(from, 0, skb_put(to, len), len);The BUG_ON() has been in that spot since af2806f8f90a1 ("net: Export skb_zerocopy() to zerocopy from one skb to another") in 2013.
On those kernels, the path in the commit message reaches the BUG_ON():
ovs_packet_cmd_execute()
__dev_alloc_skb(NET_IP_ALIGN + len, GFP_KERNEL) /* head_frag == 0 */
... POP_ETH leaves skb->len == 0 ...
ovs_dp_upcall()
queue_userspace_packet()
skb_zerocopy(user_skb, skb, 0, 0)
BUG_ON(!from->head_frag && !hlen)With the current tag, stable tooling would only pick this up for trees that already return -EFAULT. Wouldn't every stable tree without 433380f5ab8f keep a BUG() that a user can trigger from their own namespace?
Should this carry Fixes: af2806f8f90a1 instead, or the OVS Ethernet push/pop commit that made an empty-skb upcall reachable? It should also probably have Cc: stable and go through net rather than net-next.
A stable backport would also need to move the old BUG_ON() below the len <= skb_tailroom(to) return, since those trees don't have the -EFAULT conversion.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 8/15 net: skbuff: make skb_try_coalesce()'s len unsigned
In reply to Josef Bacikskb_try_coalesce() keeps from->len, which is unsigned, in an int. A corrupt from->len above INT_MAX turns negative and gets past the len <= skb_tailroom(to) check. Commit 279877d86c82 ("net: skbuff:
don't BUG() when skb_copy_bits() fails in copy helpers") moved the copy into the tailroom ahead of skb_put(), so that check is now the only thing left in the way: skb_copy_bits() clamps its copy to the negative length, and memcpy() takes it as an unsigned int, so it becomes a ~2GB write past the end of @to. Before that commit skb_put() ran first, and its overflow check caught such a length before anything was copied.
Keep len unsigned, like from->len. skb_tailroom() is never negative, so the tailroom check then refuses such a length, and every other use of len already takes an unsigned value. The truesize sanity check compares the int delta against len; spell out its delta < 0 case so a negative delta still warns now that the comparison is unsigned.
Found by the Sashiko AI review of v2 of the series that made the change.
--- net/core/skbuff.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/core/skbuff.c +3 -2
@@ -6392,7 +6392,8 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, bool *fragstolen, int *delta_truesize) { struct skb_shared_info *to_shinfo, *from_shinfo; -int i, delta, len = from->len; +unsigned int len = from->len; +int i, delta; *fragstolen = false;
@@ -6463,7 +6464,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, delta = from->truesize -SKB_TRUESIZE (skb_end_offset (from)); } -WARN_ON_ONCE (delta < len); +WARN_ON_ONCE (delta <0 || delta < len); memcpy(to_shinfo->frags + to_shinfo->nr_frags, from_shinfo->frags,
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 08/15] net: skbuff: make skb_try_coalesce()'s len unsigned
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message gets the bug's history wrong, so the single
Fixes: tag (279877d86c82) is incomplete.
--
net: skbuff: make skb_try_coalesce()'s len unsigned
This changes the local len in skb_try_coalesce() from int to unsigned int, so a from->len above INT_MAX can no longer pass the skb_tailroom() check. It also adds an explicit delta < 0 test to the truesize WARN_ON_ONCE(), since that comparison is now unsigned.
Quoted 3 lines
Before that commit
skb_put()ran first,
and its overflow check caught such a length before anything was copied.
[Severity: Low]
Is this accurate on all configurations? Before 279877d86c82, skb_try_coalesce() looked like this:
if (len <= skb_tailroom(to) && skb_frags_readable(from)) {
if (len)
BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len));len was already a signed int at that point. A from->len above INT_MAX passed the tailroom check then, the same way it does now.
skb_put() then does:
skb->tail += len; skb->len += len; if (unlikely(skb->tail > skb->end)) skb_over_panic(skb, len, __builtin_return_address(0));
On 32-bit, sk_buff_data_t is unsigned char *. A lowmem tail at or above 0x80000000 plus a len at or above 0x80000000 wraps below end, so skb_over_panic() is never called. skb_put() returns the old tail, and skb_copy_bits() runs with the negative len. That is the same large write past @to that the commit message attributes to 279877d86c82.
On 64-bit, tail and end are u32 offsets. A from->len in the range [2^32 - tail, 2^32) also wraps tail below end and gets past the check. 279877d86c82 seems to have widened this window on 64-bit, but it did not open it.
git blame shows that the signed len goes back to the introduction of the function:
bad43ca8325f4 ("net: introduce skb_try_coalesce()")
Could the commit message be corrected? Should a Fixes: tag for bad43ca8325f4 also be added? Without it, stable trees that don't contain 279877d86c82, including their 32-bit builds, may not get this fix.
Quoted 1 line
Fixes 279877d86c82 ("net: skbuff: don't BUG() when skb_copy_bits() fails in copy helpers")
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 9/15 net: skbuff: check csum_start against len in skb_copy_and_csum_dev()
In reply to Josef BacikCommit 56453199d28f ("net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev()") checks the checksum start against both ends of the linear area before copying up to it. For an skb that isn't CHECKSUM_PARTIAL, though, the checksum start is skb_headlen() itself, so the check compares it to itself and can't fail. If data_len is bigger than len, skb_headlen() underflows to about 4GB, and that becomes the length skb_copy_from_linear_data() copies into the driver's bounce buffer.
The old BUG_ON() had the same blind spot. Also check the checksum start against skb->len, so such an skb takes the existing fallback, which copies at most skb->len bytes without filling in the checksum.
Found by LLM review after the series that made the change was applied.
--- net/core/skbuff.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/skbuff.c +4 -0
@@ -4103,7 +4103,11 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else csstart =skb_headlen (skb); +/* skb_headlen() underflows if data_len is bigger than len, so check +* csstart against len as well. +*/ if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + csstart > skb->len || (skb->ip_summed ==CHECKSUM_PARTIAL && csstart + skb->csum_offset +sizeof (__sum16) > skb->len))) {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 09/15] net: skbuff: check csum_start against len in skb_copy_and_csum_dev()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] net: skbuff: incomplete headlen underflow check in skb_copy_and_csum_dev()
--
Quoted 6 lines
net/core/skbuff.c +0
-0@@ -4103,7 +4103,11 @@ void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)else
net/core/skbuff.c void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to) · line 4113
Quoted 10 lines
net/core/skbuff.c +4
-0csstart =skb_headlen (skb); +/* skb_headlen() underflows if data_len is bigger than len, so check +* csstart against len as well. +*/ if (unlikely (csstart <0 || csstart >skb_headlen (skb) || + csstart > skb->len || (skb->ip_summed ==CHECKSUM_PARTIAL && csstart + skb->csum_offset +sizeof (__sum16) > skb->len))) {
[Severity: Medium]
This only closes the hole for the non-CHECKSUM_PARTIAL case. If skb->data_len > skb->len and ip_summed is CHECKSUM_PARTIAL, csstart comes from skb_checksum_start_offset() instead of skb_headlen(), so it can be anywhere up to skb->len while skb_headlen() has wrapped to about 4GB. Both the headlen comparison and the new skb->len comparison then pass, the csum_offset check passes too, and we go straight on to skb_copy_from_linear_data(skb, to, csstart) with nothing bounding csstart by the real linear area.
skb_copy_and_csum_bits() then starts from int start = skb_headlen(skb), which is either negative, so the linear part is skipped and the frag reads are shifted by data_len - len bytes, or, once the difference exceeds INT_MAX, a bogus positive value that lets it copy from skb->data past the end of the linear data.
The fallback isn't safe either. skb_copy_bits() also begins with int start = skb_headlen(skb), so sending such an skb down the existing fallback, as the changelog describes, bounds the writes to @to by skb->len but not the reads from the skb.
Since the condition you really want to catch is data_len > len, would it be simpler to test that directly before computing csstart, and memset() @to rather than calling skb_copy_bits() in that case? Or should skb_copy_bits() and skb_copy_and_csum_bits() reject data_len > len themselves?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 10/15 net: skbuff: reject a negative length in skb_copy_and_csum_bits()
In reply to Josef BacikCommit 417261779eab ("net: skbuff: don't BUG() on leftover length in skb_copy_and_csum_bits()") guards its zero-fill against a negative @len from a broken caller, but such a @len never gets that far. The head, frag and frag_list copies all clamp their length to @len, so a negative one has already turned into a huge copy, or an endless frag walk, by then.
Reject a negative @len on entry with -EINVAL, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels, and drop the guard on the zero-fill that can no longer be reached with one. Every caller already handles an error from skb_copy_and_csum_bits().
Found by the Sashiko AI review of v2 of the series that made the change.
--- net/core/skbuff.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
net/core/skbuff.c +13 -5
@@ -3678,9 +3678,10 @@ EXPORT_SYMBOL(skb_checksum);* @len: number of bytes to copy * @csump: where to store the checksum of the copied bytes * -* Return: 0 on success, or -EFAULT if @skb has unreadable frags or runs -* out before @len does. On failure *@csump is not set and the part of -* @to that couldn't be filled is zeroed. +* Return: 0 on success, -EINVAL if @len is negative, or -EFAULT if @skb +* has unreadable frags or runs out before @len does. On failure *@csump +* is not set, and on -EFAULT the part of @to that couldn't be filled is +* zeroed. */ int skb_copy_and_csum_bits (const struct sk_buff *skb,int offset,u8 *to,int len,__wsum *csump)
@@ -3692,6 +3693,14 @@ int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,__wsum csum =0 ;int err; +/* Everything below clamps copies to @len, so a negative one would +* turn into a huge copy. +*/ +if (unlikely (len <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + } +/* Copy header. */ if (copy >0 ) {if (copy > len)
@@ -3777,8 +3786,7 @@ int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,if (unlikely (len)) {DEBUG_NET_WARN_ON_ONCE (1 );/* Don't hand the caller a buffer with stale bytes in it. */ -if (len >0 ) -memset (to,0 , len); +memset (to,0 , len);return -EFAULT ; } out:
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next 10/15] net: skbuff: reject a negative length in skb_copy_and_csum_bits()
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message's reason for dropping the if (len > 0) guard on the final zero-fill in skb_copy_and_csum_bits() (net/core/skbuff.c)…
- [Low] The patch narrows the zero-fill promise in skb_copy_and_csum_bits()'s kernel-doc: "on -EFAULT the part of @to…
--
net: skbuff: reject a negative length in skb_copy_and_csum_bits()
This commit makes skb_copy_and_csum_bits() return -EINVAL, with a DEBUG_NET_WARN_ON_ONCE(), when it is given a negative len. It also drops the len > 0 guard on the final zero-fill. The kernel-doc now promises the zero-fill only for -EFAULT.
Quoted 6 lines
Commit
417261779eab("net: skbuff: don'tBUG()on leftover length inskb_copy_and_csum_bits()") guards its zero-fill against a negative @len from a broken caller, but such a @len never gets that far. The head, frag andfrag_listcopies all clamp their length to @len, so a negative one has already turned into a huge copy, or an endless frag walk, by then.
[Severity: Low]
Is this an accurate description of the old code? The head, frag and frag_list copies clamp to len only when they run. All three are skipped when offset is at or past the end of the skb's data.
Take a linear skb with no frags, offset == skb->len and len == -1:
copy = start - offset; /* 0, no head copy */
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) /* no frags */
skb_walk_frags(skb, frag_iter) /* empty */In the parent commit, the negative len then reaches the final block unchanged:
net/core/skbuff.c:skb_copy_and_csum_bits() {
...
if (unlikely(len)) {
DEBUG_NET_WARN_ON_ONCE(1);
/* Don't hand the caller a buffer with stale bytes in it. */
if (len > 0)
memset(to, 0, len);
return -EFAULT;
}
...
}There, the len > 0 check is what prevents a memset of close to SIZE_MAX bytes.
The code change itself looks right, because the new check on entry keeps len non-negative for the rest of the function. The Fixes: tag relies on this description of what 417261779eab guarded, though. Could the commit message say that the guard only covered the final zero-fill and not the clamped copies?
Quoted 19 lines
net/core/skbuff.c +4
-3@@ -3678,9 +3678,10 @@ EXPORT_SYMBOL(skb_checksum);* @len: number of bytes to copy * @csump: where to store the checksum of the copied bytes * -* Return: 0 on success, or -EFAULT if @skb has unreadable frags or runs -* out before @len does. On failure *@csump is not set and the part of -* @to that couldn't be filled is zeroed. +* Return: 0 on success, -EINVAL if @len is negative, or -EFAULT if @skb +* has unreadable frags or runs out before @len does. On failure *@csump +* is not set, and on -EFAULT the part of @to that couldn't be filled is +* zeroed. */ int skb_copy_and_csum_bits (const struct sk_buff *skb,int offset,u8 *to,int len,__wsum *csump)
net/core/skbuff.c int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, · line 3702
Quoted 10 lines
net/core/skbuff.c +7
-0@@ -3692,6 +3693,14 @@ int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,__wsum csum =0 ;int err; +/* Everything below clamps copies to @len, so a negative one would +* turn into a huge copy. +*/ +if (unlikely (len <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }
[Severity: Low]
This early return leaves to untouched, and the kernel-doc above now promises the zero-fill only for -EFAULT. Does skb_copy_and_csum_dev() need an update as well? Its comment still says that any failure zeroes the buffer:
net/core/skbuff.c:skb_copy_and_csum_dev() {
...
csum = 0;
/* On failure the rest of @to is zeroed; leave the checksum alone so
* the frame goes out with a bad one.
*/
if (csstart != skb->len &&
skb_copy_and_csum_bits(skb, csstart, to + csstart,
skb->len - csstart, &csum))
return;
...
}The drivers that call it (8139too, via-rhine, sc92031, ep93xx, ec_bhf, ksz884x) transmit to after it returns. The csstart checks keep skb->len - csstart non-negative as an unsigned value, but they don't keep it within INT_MAX. A corrupt skb with more than INT_MAX bytes past csstart would get -EINVAL here, and the bytes after csstart would go out stale.
That also goes against the first patch in the series ("net: skbuff: make skb_copy_and_csum_bits() report unreadable frags"), which says "The zero-fill stays, so a caller that does send the buffer still doesn't leak anything."
The drivers' own size limits keep valid skbs from getting here. Before this patch, the same corrupt input caused a huge copy instead. The comment in skb_copy_and_csum_dev() is still unchanged at the end of the series, including after "net: update comments that still describe the skb BUG_ON()s".
Could that comment be updated? Alternatively, skb_copy_and_csum_dev() could zero the rest of to itself when the helper fails.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 11/15 net: skbuff: refuse to segment a nested frag_list
In reply to Josef Bacikskb_segment() walks head_skb's frag_list, but for each member it only looks at the linear part and frags[], never at the member's own frag_list. head_skb->len still counts those bytes, so with a nested frag_list the walk runs out of members while it still owes data, sets list_skb to NULL, and dereferences it on the next pass, before any of the layout checks get a chance to catch it.
Nothing in the tree is known to build such an skb; GRO flushes instead of chaining an skb that already has a frag_list. Check for it up front and fail the segmentation with -EINVAL, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels, like the other frag_list layout checks.
--- net/core/skbuff.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
net/core/skbuff.c +21 -0
@@ -4962,6 +4962,17 @@ struct sk_buff *skb_segment_list(struct sk_buff *skb, }EXPORT_SYMBOL_GPL (skb_segment_list); +/* skb_segment() only walks one level of frag_list. */ +static bool skb_segment_nested_frag_list (const struct sk_buff *head_skb) +{ +const struct sk_buff *iter; + + skb_walk_frags(head_skb, iter) +if (skb_has_frag_list (iter)) +return true; +return false; +} +/** * skb_segment - Perform protocol segmentation on skb. * @head_skb: buffer to segment
@@ -5023,6 +5034,16 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, sg = !!(features &NETIF_F_SG ); csum = !!can_checksum_protocol (features, proto); +/* The walk below never looks inside a member's own frag_list, but +* head_skb->len counts those bytes, so it would run out of members +* and dereference a NULL list_skb. +*/ +if (unlikely (list_skb &&skb_segment_nested_frag_list (head_skb))) { +DEBUG_NET_WARN_ON_ONCE (1 ); + err = -EINVAL ; + goto err; + } +if (sg && csum && !gso_by_frags) {if (!max_segs && !(features &NETIF_F_GSO_PARTIAL )) {struct sk_buff *iter;
Signature · 1 line
2.55.0
Re: [PATCH net-next 11/15] net: skbuff: refuse to segment a nested frag_list
Quoted 24 lines · Josef Bacik
skb_segment()walks head_skb'sfrag_list, but for each member it only looks at the linear part and frags[], never at the member's ownfrag_list.head_skb->lenstill counts those bytes, so with a nestedfrag_listthe walk runs out of members while it still owes data, setslist_skbto NULL, and dereferences it on the next pass, before any of the layout checks get a chance to catch it.Nothing in the tree is known to build such an skb; GRO flushes instead of chaining an skb that already has a
frag_list. Check for it up front and fail the segmentation with-EINVAL, with aDEBUG_NET_WARN_ON_ONCE()for debug kernels, like the otherfrag_listlayout checks.Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- net/core/skbuff.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)net/core/skbuff.c +0
-0@@ -4962,6 +4962,17 @@ struct sk_buff *skb_segment_list(struct sk_buff *skb, }
net/core/skbuff.c struct sk_buff *skb_segment_list(struct sk_buff *skb, · line 4972
Quoted 10 lines
net/core/skbuff.c +8
-0EXPORT_SYMBOL_GPL (skb_segment_list); +/* skb_segment() only walks one level of frag_list. */ +static bool skb_segment_nested_frag_list (const struct sk_buff *head_skb) +{ +const struct sk_buff *iter; + + skb_walk_frags(head_skb, iter) +if (skb_has_frag_list (iter)) +return true;
We can probably check the same without adding an extra skb_walk_frags.
Perhaps
@@ -5025,6 +5025,12 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
while (pos < offset + len) {
if (i >= nfrags) {
+ if (unlikely(!list_skb || skb_has_frag_list(list_skb))) {
+ DEBUG_NET_WARN_ON_ONCE(1);
+ err = -EINVAL;
+ goto err;+ }
+
Quoted 27 lines
net/core/skbuff.c +13
-0+return false; +} +/** * skb_segment - Perform protocol segmentation on skb. * @head_skb: buffer to segment @@ -5023,6 +5034,16 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, sg = !!(features &NETIF_F_SG ); csum = !!can_checksum_protocol (features, proto); +/* The walk below never looks inside a member's own frag_list, but +* head_skb->len counts those bytes, so it would run out of members +* and dereference a NULL list_skb. +*/ +if (unlikely (list_skb &&skb_segment_nested_frag_list (head_skb))) { +DEBUG_NET_WARN_ON_ONCE (1 ); + err = -EINVAL ; + goto err; + } +if (sg && csum && !gso_by_frags) {if (!max_segs && !(features &NETIF_F_GSO_PARTIAL )) {struct sk_buff *iter;Signature · 2 lines
-- 2.55.0
[email protected]
AI reviewRe: [PATCH net-next 11/15] net: skbuff: refuse to segment a nested frag_list
In reply to Josef BacikThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message for "net: skbuff: refuse to segment a nested frag_list" says "Nothing in the tree is known to build such an skb;…
--
net: skbuff: refuse to segment a nested frag_list
This adds a check to skb_segment() that rejects an skb whose frag_list members have frag_lists of their own. It fails with -EINVAL and calls DEBUG_NET_WARN_ON_ONCE(), since the segmentation walk would otherwise run out of members and dereference a NULL list_skb.
Quoted 2 lines
Nothing in the tree is known to build such an skb; GRO flushes instead of chaining an skb that already has a
frag_list. Check for it up front
[Severity: Low]
Is the first half of this sentence accurate as a general statement?
IP fragment reassembly appears to build exactly this layout. When the first fragment already has a frag_list, inet_frag_reasm_prepare() moves that frag_list under a new zero-length skb:
net/ipv4/inet_fragment.c:inet_frag_reasm_prepare() {
...
if (skb_has_frag_list(head)) {
struct sk_buff *clone;
...
clone = alloc_skb(0, GFP_ATOMIC);
...
skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
skb_frag_list_init(head);
...
skb_shinfo(head)->frag_list = clone;
nextp = &clone->next;
...
}The result is head -> frag_list[clone -> frag_list[...]]. That is the nested layout the new check in skb_segment() rejects.
The GRO part is correct. dev_gro_receive() sets:
NAPI_GRO_CB(skb)->flush = skb_has_frag_list(skb);
Reassembled skbs are not GSO, so they don't normally reach skb_segment(). The narrower claim seems to be what's meant: no in-tree path builds a GSO skb with a nested frag_list.
Could the commit message say that instead, and mention IP defrag as a known non-GSO source of nested frag_lists?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 12/15 net: test the frag_list layouts skb_segment() refuses
In reply to Josef BacikThe GSO KUnit test only checks layouts skb_segment() can segment. Add two it has to refuse with -EINVAL: the non-uniform frag_list with SG on, which used to hit the BUG_ON(i >= nfrags) the existing test steps around, and a frag_list member that has its own frag_list.
Both warn on CONFIG_DEBUG_NET kernels, so run them with the warning backtrace suppressed.
--- net/core/net_test.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
net/core/net_test.c +48 -0
@@ -39,6 +39,8 @@ enum gso_test_nr {GSO_TEST_RESEGMENT_MULTI ,GSO_TEST_RESEGMENT_TAIL ,GSO_TEST_RESEGMENT_ONE_MSS , +GSO_TEST_FRAG_LIST_NON_UNIFORM_SG , + GSO_TEST_FRAG_LIST_NESTED, }; struct gso_test_case {
@@ -57,6 +59,9 @@ struct gso_test_case {unsigned int nr_segs;const unsigned int *segs;const unsigned int *gso_segs; + +/* skb_segment() is expected to fail with this error */ +int err; };static struct gso_test_case cases[] = {
@@ -204,6 +209,28 @@ static struct gso_test_case cases[] = { }, .gso_segs = (const unsigned int[]) { 0, 0, 0, 0 }, }, + { +/* frag_list members that don't end on gso_size boundaries +* can't be segmented with SG +*/ + .id = GSO_TEST_FRAG_LIST_NON_UNIFORM_SG, + .name = "frag_list_non_uniform_sg", + .linear_len = GSO_TEST_SIZE, + .nr_frag_skbs = 4, + .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, 1, GSO_TEST_SIZE, 2 }, + .err = -EINVAL, + }, + { +/* the second frag_list member hangs off the first one's +* frag_list instead of off the head's +*/ + .id = GSO_TEST_FRAG_LIST_NESTED, + .name = "frag_list_nested", + .linear_len = GSO_TEST_SIZE, + .nr_frag_skbs = 2, + .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE }, + .err = -EINVAL, + }, };static void gso_test_case_to_desc (struct gso_test_case *t,char *desc)
@@ -283,6 +310,15 @@ static void gso_test_func(struct kunit *test)if (tcase->id ==GSO_TEST_GSO_BY_FRAGS )skb_shinfo (skb)->gso_size =GSO_BY_FRAGS ; + +if (tcase->id ==GSO_TEST_FRAG_LIST_NESTED ) { +struct sk_buff *first =skb_shinfo (skb)->frag_list; + +skb_shinfo (first)->frag_list = first->next; + first->next =NULL ; + first->len += tcase->frag_skbs[1 ]; + first->data_len += tcase->frag_skbs[1 ]; + } } features =NETIF_F_SG |NETIF_F_HW_CSUM ;
@@ -296,6 +332,18 @@ static void gso_test_func(struct kunit *test) features &= ~NETIF_F_SG ;SKB_GSO_CB (skb)->max_segs = tcase->max_segs; + +if (tcase->err) { +/* the suppression block doesn't run if it can't be set up */ + segs =NULL ; +kunit_warning_suppress (test) + segs =skb_segment (skb, features); +KUNIT_EXPECT_EQ (test,PTR_ERR_OR_ZERO (segs), tcase->err); +if (!IS_ERR_OR_NULL (segs)) +kfree_skb_list (segs); + goto free_gso_skb; + } + segs =skb_segment (skb, features);if (IS_ERR (segs)) {KUNIT_FAIL (test,"segs error %pe" , segs);
Signature · 1 line
2.55.0
Re: [PATCH net-next 12/15] net: test the frag_list layouts skb_segment() refuses
Quoted 10 lines · Josef Bacik
The GSO KUnit test only checks layouts
skb_segment()can segment. Add two it has to refuse with-EINVAL: the non-uniformfrag_listwith SG on, which used to hit theBUG_ON(i >= nfrags)the existing test steps around, and afrag_listmember that has its ownfrag_list.Both warn on
CONFIG_DEBUG_NETkernels, so run them with the warning backtrace suppressed.Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>
Thanks!
Quoted 73 lines
--- net/core/net_test.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)net/core/net_test.c +36
-0@@ -39,6 +39,8 @@ enum gso_test_nr {GSO_TEST_RESEGMENT_MULTI ,GSO_TEST_RESEGMENT_TAIL ,GSO_TEST_RESEGMENT_ONE_MSS , +GSO_TEST_FRAG_LIST_NON_UNIFORM_SG , + GSO_TEST_FRAG_LIST_NESTED, }; struct gso_test_case {@@ -57,6 +59,9 @@ struct gso_test_case {unsigned int nr_segs;const unsigned int *segs;const unsigned int *gso_segs; + +/* skb_segment() is expected to fail with this error */ +int err; };static struct gso_test_case cases[] = {@@ -204,6 +209,28 @@ static struct gso_test_case cases[] = { }, .gso_segs = (const unsigned int[]) { 0, 0, 0, 0 }, }, + { +/* frag_list members that don't end on gso_size boundaries +* can't be segmented with SG +*/ + .id = GSO_TEST_FRAG_LIST_NON_UNIFORM_SG, + .name = "frag_list_non_uniform_sg", + .linear_len = GSO_TEST_SIZE, + .nr_frag_skbs = 4, + .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, 1, GSO_TEST_SIZE, 2 }, + .err = -EINVAL, + }, + { +/* the second frag_list member hangs off the first one's +* frag_list instead of off the head's +*/ + .id = GSO_TEST_FRAG_LIST_NESTED, + .name = "frag_list_nested", + .linear_len = GSO_TEST_SIZE, + .nr_frag_skbs = 2, + .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE }, + .err = -EINVAL, + }, };static void gso_test_case_to_desc (struct gso_test_case *t,char *desc)@@ -283,6 +310,15 @@ static void gso_test_func(struct kunit *test)if (tcase->id ==GSO_TEST_GSO_BY_FRAGS )skb_shinfo (skb)->gso_size =GSO_BY_FRAGS ; + +if (tcase->id ==GSO_TEST_FRAG_LIST_NESTED ) { +struct sk_buff *first =skb_shinfo (skb)->frag_list; + +skb_shinfo (first)->frag_list = first->next; + first->next =NULL ; + first->len += tcase->frag_skbs[1 ]; + first->data_len += tcase->frag_skbs[1 ]; + } } features =NETIF_F_SG |NETIF_F_HW_CSUM ;
net/core/net_test.c static void gso_test_func(struct kunit *test) · line 340
Quoted 9 lines
net/core/net_test.c +6
-0@@ -296,6 +332,18 @@ static void gso_test_func(struct kunit *test) features &= ~NETIF_F_SG ;SKB_GSO_CB (skb)->max_segs = tcase->max_segs; + +if (tcase->err) { +/* the suppression block doesn't run if it can't be set up */ + segs =NULL ; +kunit_warning_suppress (test) + segs =skb_segment (skb, features);
nit: if respinning, add braces
Quoted 13 lines
net/core/net_test.c +6
-0+KUNIT_EXPECT_EQ (test,PTR_ERR_OR_ZERO (segs), tcase->err); +if (!IS_ERR_OR_NULL (segs)) +kfree_skb_list (segs); + goto free_gso_skb; + } + segs =skb_segment (skb, features);if (IS_ERR (segs)) {KUNIT_FAIL (test,"segs error %pe" , segs);Signature · 2 lines
-- 2.55.0
PATCH 13/15 xen-netfront: don't BUG() when skb_copy_bits() fails in bounce_skb()
In reply to Josef Bacikbounce_skb() is an open-coded skb_copy() for skbs whose data isn't page-aligned, and it has the same BUG_ON(skb_copy_bits()). skb_copy_bits() only fails when the skb's lengths don't add up.
bounce_skb() already frees the new skb and returns NULL when the allocation comes back misaligned, and xennet_start_xmit() drops the packet in that case. Take the same path, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels.
--- drivers/net/xen-netfront.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/xen-netfront.c +6 -1
@@ -695,7 +695,12 @@ static struct sk_buff *bounce_skb(const struct sk_buff *skb)/* Set the tail pointer and length */ skb_put (n, skb->len); -BUG_ON (skb_copy_bits (skb, -headerlen, n->head, headerlen + skb->len)); +if (unlikely (skb_copy_bits (skb, -headerlen, n->head, + headerlen + skb->len))) { +DEBUG_NET_WARN_ON_ONCE (1 ); +kfree_skb (n); +return NULL ; + }skb_copy_header (n, skb);return n;
Signature · 1 line
2.55.0
PATCH 14/15 net/tls: don't BUG() on leftover length in __skb_nsg()
In reply to Josef Bacik__skb_nsg() counts the scatterlist entries for a range of an skb with a copy of the __skb_to_sgvec() walk, including its BUG_ON(len) when the skb runs out before the range does. tls_decrypt_sg() calls it on the same range it then passes to skb_to_sgvec(), so a bad range would BUG() here before it got to skb_to_sgvec()'s error return.
__skb_nsg() already returns -EMSGSIZE for a frag_list nested too deep, and tls_decrypt_sg() fails the record on any return below 1. Return -EINVAL for the leftover length too, with a DEBUG_NET_WARN_ON_ONCE() for debug kernels.
--- net/tls/tls_sw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/tls/tls_sw.c +4 -1
@@ -142,7 +142,10 @@ static int __skb_nsg(struct sk_buff *skb, int offset, int len, start = end; } } -BUG_ON (len); +if (unlikely (len)) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }return elt; }
Signature · 1 line
2.55.0
Re: [PATCH net-next 14/15] net/tls: don't BUG() on leftover length in __skb_nsg()
Quoted 23 lines · Josef Bacik
__skb_nsg()counts the scatterlist entries for a range of an skb with a copy of the__skb_to_sgvec()walk, including itsBUG_ON(len)when the skb runs out before the range does.tls_decrypt_sg()calls it on the same range it then passes toskb_to_sgvec(), so a bad range wouldBUG()here before it got to skb_to_sgvec()'s error return.
__skb_nsg()already returns-EMSGSIZEfor afrag_listnested too deep, andtls_decrypt_sg()fails the record on any return below 1. Return-EINVALfor the leftover length too, with aDEBUG_NET_WARN_ON_ONCE()for debug kernels.Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- net/tls/tls_sw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/tls/tls_sw.c +0
-0
net/tls/tls_sw.c static int __skb_nsg(struct sk_buff *skb, int offset, int len, · line 148
Quoted 8 lines
net/tls/tls_sw.c +4
-1@@ -142,7 +142,10 @@ static int __skb_nsg(struct sk_buff *skb, int offset, int len, start = end; } } -BUG_ON (len); +if (unlikely (len)) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }
Ugh, why DEBUG_NET_WARN...? Seems WARN_ON_ONCE() is more appropriate, after all we're downgrading from a BUG_ON(). Another nice thing is that it could have been done inline:
if (unlikely(WARN_ON_ONCE(len)))
return -EINVAL;
But I suppose it doesn't matter much
Signature · 2 lines
Thanks, Mina
Re: [PATCH net-next 14/15] net/tls: don't BUG() on leftover length in __skb_nsg()
Quoted 29 lines · Mina Almasry
Quoted 27 lines · Josef Bacik
__skb_nsg()counts the scatterlist entries for a range of an skb with a copy of the__skb_to_sgvec()walk, including itsBUG_ON(len)when the skb runs out before the range does.tls_decrypt_sg()calls it on the same range it then passes toskb_to_sgvec(), so a bad range wouldBUG()here before it got to skb_to_sgvec()'s error return.
__skb_nsg()already returns-EMSGSIZEfor afrag_listnested too deep, andtls_decrypt_sg()fails the record on any return below 1. Return-EINVALfor the leftover length too, with aDEBUG_NET_WARN_ON_ONCE()for debug kernels.Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- net/tls/tls_sw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/tls/tls_sw.c +0
-1@@ -142,7 +142,10 @@ static int __skb_nsg(struct sk_buff *skb, int offset, int len, start = end; } } -BUG_ON (len);
Quoted 8 lines
net/tls/tls_sw.c static int __skb_nsg(struct sk_buff *skb, int offset, int len, · line 148
Quoted 4 lines
net/tls/tls_sw.c +4
-0+if (unlikely (len)) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }Ugh, why
DEBUG_NET_WARN...? SeemsWARN_ON_ONCE()is more appropriate, after all we're downgrading from aBUG_ON(). Another nice thing is that it could have been done inline:
Because that still triggers on systems with panic_on_warn. See also
Re: [PATCH net-next 14/15] net/tls: don't BUG() on leftover length in __skb_nsg()
Quoted 40 lines · Willem de Bruijn
Quoted 29 lines · Mina Almasry
Quoted 27 lines · Josef Bacik
__skb_nsg()counts the scatterlist entries for a range of an skb with a copy of the__skb_to_sgvec()walk, including itsBUG_ON(len)when the skb runs out before the range does.tls_decrypt_sg()calls it on the same range it then passes toskb_to_sgvec(), so a bad range wouldBUG()here before it got to skb_to_sgvec()'s error return.
__skb_nsg()already returns-EMSGSIZEfor afrag_listnested too deep, andtls_decrypt_sg()fails the record on any return below 1. Return-EINVALfor the leftover length too, with aDEBUG_NET_WARN_ON_ONCE()for debug kernels.Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>--- net/tls/tls_sw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/tls/tls_sw.c +0
-1@@ -142,7 +142,10 @@ static int __skb_nsg(struct sk_buff *skb, int offset, int len, start = end; } } -BUG_ON (len);Quoted 8 lines
net/tls/tls_sw.c static int __skb_nsg(struct sk_buff *skb, int offset, int len, · line 148
Quoted 4 lines
net/tls/tls_sw.c +4
-0+if (unlikely (len)) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }Ugh, why
DEBUG_NET_WARN...? SeemsWARN_ON_ONCE()is more appropriate, after all we're downgrading from aBUG_ON(). Another nice thing is that it could have been done inline:
Quoted 3 lines
Because that still triggers on systems with
panic_on_warn. See also
Heh, looks like we have the opposite instincts here and I missed the initial conversation. DEBUG_NET_WARN_ is fine by me too. Thanks!
Signature · 2 lines
Thanks, Mina
[email protected]
AI reviewRe: [PATCH net-next 14/15] net/tls: don't BUG() on leftover length in __skb_nsg()
In reply to Josef BacikThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In net/tls/tls_sw.c, the comment above skb_nsg() is now out of date.
--
net/tls: don't BUG() on leftover length in __skb_nsg()
This patch replaces the BUG_ON(len) in __skb_nsg() with a DEBUG_NET_WARN_ON_ONCE() and an -EINVAL return. A range that runs past the end of the skb now fails the record in tls_decrypt_sg() instead of crashing the kernel.
Quoted 6 lines
net/tls/tls_sw.c +0
-0@@ -142,7 +142,10 @@ static int __skb_nsg(struct sk_buff *skb, int offset, int len, start = end;
net/tls/tls_sw.c static int __skb_nsg(struct sk_buff *skb, int offset, int len, · line 151
Quoted 10 lines
net/tls/tls_sw.c +4
-1} } -BUG_ON (len); +if (unlikely (len)) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + }return elt; }
[Severity: Low]
This isn't a bug, but should the comment above skb_nsg() be updated to cover the new return value? The comment directly below this hunk still says:
net/tls/tls_sw.c:
/* Return the number of scatterlist elements required to completely map the
* skb, or -EMSGSIZE if the recursion depth is exceeded.
*/
static int skb_nsg(struct sk_buff *skb, int offset, int len)
{
return __skb_nsg(skb, offset, len, 0);
}skb_nsg() returns whatever __skb_nsg() returns. The recursive frag_list calls also pass negative values straight up:
if (unlikely(ret < 0))
return ret;So skb_nsg() can now return -EINVAL when the skb runs out before the requested range does.
The only caller, tls_decrypt_sg(), already handles any negative value:
if (n_sgin < 1)
return n_sgin ?: -EBADMSG;So this doesn't change behavior at runtime.
The comment is also still unchanged at the end of the series, including after the last patch, "net: update comments that still describe the skb BUG_ON()s".
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-b4-skbuff-bug-on-followups-v1-0-41dbef50b9f7%40toxicpanda.com
PATCH 15/15 net: update comments that still describe the skb BUG_ON()s
In reply to Josef BacikThe skbuff BUG_ON() conversions left a few comments behind:
- bpf_skb_net_grow() says skb_segment() BUG()s on a frag_list with head_frag set at the downgraded MSS. It fails the segmentation and the packet is dropped, which is still why the skb gets linearized.
- The GSO KUnit test says the non-uniform frag_list case would hit BUG_ON(i >= nfrags) with SG. That check now fails with -EINVAL.
- The skb_to_sgvec() kernel-doc doesn't list the -EINVAL that __skb_to_sgvec() returns when @offset and @len run past the end of the skb.
No functional change.
--- net/core/filter.c | 6 +++--- net/core/net_test.c | 4 ++-- net/core/skbuff.c | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-)
net/core/filter.c +3 -3
@@ -3696,9 +3696,9 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff, shinfo->gso_segs =0 ;/* Due to header growth, MSS needs to be downgraded. -* There is a BUG_ON() when segmenting the frag_list with -* head_frag true, so linearize the skb after downgrading -* the MSS. +* Segmenting a frag_list with head_frag true at the new MSS +* fails and the packet gets dropped, so linearize the skb +* after downgrading the MSS. */ if (!(flags &BPF_F_ADJ_ROOM_FIXED_GSO )) {skb_decrease_gso_size (shinfo, len_diff);
net/core/net_test.c +2 -2
@@ -325,8 +325,8 @@ static void gso_test_func(struct kunit *test)if (tcase->id ==GSO_TEST_GSO_PARTIAL ) features |=NETIF_F_GSO_PARTIAL ; -/* TODO: this should also work with SG, -* rather than hit BUG_ON(i >= nfrags) +/* TODO: this should also work with SG, rather than fail the +* i >= nfrags check in skb_segment() */ if (tcase->id ==GSO_TEST_FRAG_LIST_NON_UNIFORM ) features &= ~NETIF_F_SG ;
net/core/skbuff.c +3 -2
@@ -5554,8 +5554,9 @@ __skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len,* * Fill the specified scatter-gather list with mappings/pointers into a * region of the buffer space attached to a socket buffer. Returns either -* the number of scatterlist items used, or -EMSGSIZE if the contents -* could not fit. +* the number of scatterlist items used, -EMSGSIZE if the contents +* could not fit, or -EINVAL if @offset and @len run past the end of +* the skb. */ int skb_to_sgvec (struct sk_buff *skb,struct scatterlist *sg,int offset,int len) {
Signature · 1 line
2.55.0
Re: [PATCH net-next 15/15] net: update comments that still describe the skb BUG_ON()s
Quoted 12 lines · Josef Bacik
The skbuff
BUG_ON()conversions left a few comments behind:-
bpf_skb_net_grow()saysskb_segment()BUG()s on afrag_listwithhead_fragset at the downgraded MSS. It fails the segmentation and the packet is dropped, which is still why the skb gets linearized.
- The GSO KUnit test says the non-uniformfrag_listcase would hitBUG_ON(i >= nfrags)with SG. That check now fails with-EINVAL.
- Theskb_to_sgvec()kernel-doc doesn't list the-EINVALthat__skb_to_sgvec()returns when @offset and @len run past the end of the skb.
Quoted 4 lines
No functional change.
Assisted-by LLMSigned-off-by Josef Bacik <[email protected]>
I would have preferred this change is squashed with the code change; if you re-spin for another reason maybe do that.