net: skbuff: do not leave stale header offsets after pskb_carve()
Subsystems (2)
PATCH v2 1/1 net: skbuff: do not leave stale header offsets after pskb_carve()
pskb_carve_inside_header() and pskb_carve_inside_nonlinear() remove the first bytes of a packet and reallocate skb->head.
All the headers that were present before the operation are gone, but both functions call skb_headers_offset_update(skb, 0), which is a no-op : skb->mac_header, skb->network_header, skb->transport_header and skb->csum_start keep their old values and now describe bytes which are no longer there.
Both helpers size the new head from the old skb_end_offset(), so the stale offsets still land inside the new allocation. They point past skb_tail_pointer() though, to bytes that were never initialized.
pskb_carve_inside_nonlinear() is the worst case, because it leaves a zombie skb with an empty linear part (skb->data == skb_tail_pointer(skb), skb_headlen(skb) == 0), while skb_mac_header_was_set() is still true and skb->mac_header is way ahead of skb->data.
The only user of pskb_extract() is rds_tcp_data_recv(), and the carved skb is queued on tinc->ti_skb_list. When the RDS incoming message is released, rds_tcp_inc_free() calls skb_queue_purge(), which frees the skbs with SKB_DROP_REASON_QUEUE_PURGE. This is visible from drop_monitor, which then tries to pull back to the (bogus) mac header :
skbuff: __skb_pull(len=234)
skb len=6968 data_len=6968 headroom=0 headlen=0 tailroom=0 end-tail=384 mac=(234,14) mac_len=14 net=(248,40) trans=288 shinfo(txflags=0 nr_frags=1 gso(size=1428 type=16 segs=5)) csum(0x100120 start=288 offset=16 ip_summed=3 complete_sw=0 valid=1 level=0) hash(0x7b446c6c sw=0 l4=1) proto=0x86dd pkttype=0 iif=60
------------[ cut here ]------------ kernel BUG at ./include/linux/skbuff.h:2847!
Add skb_carve_reset_headers() to mark the mac and transport headers as not set, reset the network header, clear skb->mac_len, and drop a now meaningless CHECKSUM_PARTIAL (csum_start no longer describes anything).
Invalidate the inner offsets as well. Unlike mac_header and transport_header they have no "unset" sentinel, so a leftover non-zero value still looks like a real header. Zero skb->inner_mac_header, skb->inner_network_header, skb->inner_transport_header, skb->inner_protocol and skb->encapsulation, so that all the header state is invalidated in one place.
v2: fixed an inaccurate changelog. The stale offsets stay inside the
new skb->head, which is never smaller than the old one, they simply point past skb_tail_pointer() to bytes that are gone. Thanks to Xuanqiang Luo for insisting on this.
Also invalidate the inner header state, as suggested by the netdev AI review :
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260911114922.621937-1-edumazet%40google.com
--- net/core/skbuff.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
net/core/skbuff.c +30 -2
@@ -6832,6 +6832,34 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, }EXPORT_SYMBOL (alloc_skb_with_frags); +/* pskb_carve_inside_header() and pskb_carve_inside_nonlinear() +* remove the first bytes of a packet and reallocate skb->head. +* +* Whatever headers were present before the operation are gone, +* we must not leave stale offsets, otherwise users of this skb +* (skb_dump(), drop_monitor, taps, ...) would read or pull garbage. +*/ +static void skb_carve_reset_headers (struct sk_buff *skb) +{ +skb_unset_mac_header (skb); +skb_unset_transport_header (skb); +skb_reset_network_header (skb); + skb->mac_len =0 ; + +/* Inner offsets have no "unset" marker, zero them so that +* skb_inner_network_header_was_set() becomes false and no +* consumer mistakes them for a real (and long gone) header. +*/ + skb->inner_mac_header =0 ; + skb->inner_network_header =0 ; + skb->inner_transport_header =0 ; + skb->inner_protocol =0 ; + skb->encapsulation =0 ; + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) + skb->ip_summed =CHECKSUM_NONE ; +} +/* carve out the first off bytes from skb when off < headlen */ static int pskb_carve_inside_header (struct sk_buff *skb,const u32 off,const int headlen,gfp_t gfp_mask)
@@ -6887,7 +6915,7 @@ static int pskb_carve_inside_header(struct sk_buff *skb, const u32 off, skb->head_frag =0 ;skb_set_end_offset (skb, size);skb_set_tail_pointer (skb,skb_headlen (skb)); -skb_headers_offset_update (skb,0 ); +skb_carve_reset_headers (skb); skb->cloned =0 ; skb->hdr_len =0 ; skb->nohdr =0 ;
@@ -7027,7 +7055,7 @@ static int pskb_carve_inside_nonlinear(struct sk_buff *skb, const u32 off, skb->data = data;skb_set_end_offset (skb, size);skb_reset_tail_pointer (skb); -skb_headers_offset_update (skb,0 ); +skb_carve_reset_headers (skb); skb->cloned =0 ; skb->hdr_len =0 ; skb->nohdr =0 ;
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
Quoted 56 lines · Eric Dumazet
pskb_carve_inside_header()andpskb_carve_inside_nonlinear()remove the first bytes of a packet and reallocateskb->head.All the headers that were present before the operation are gone, but both functions call
skb_headers_offset_update(skb, 0), which is a no-op :skb->mac_header,skb->network_header,skb->transport_headerandskb->csum_startkeep their old values and now describe bytes which are no longer there.Both helpers size the new head from the old
skb_end_offset(), so the stale offsets still land inside the new allocation. They point pastskb_tail_pointer()though, to bytes that were never initialized.
pskb_carve_inside_nonlinear()is the worst case, because it leaves a zombie skb with an empty linear part (skb->data==skb_tail_pointer(skb),skb_headlen(skb)== 0), whileskb_mac_header_was_set()is still true andskb->mac_headeris way ahead ofskb->data.The only user of
pskb_extract()isrds_tcp_data_recv(), and the carved skb is queued ontinc->ti_skb_list. When the RDS incoming message is released,rds_tcp_inc_free()callsskb_queue_purge(), which frees the skbs withSKB_DROP_REASON_QUEUE_PURGE. This is visible fromdrop_monitor, which then tries to pull back to the (bogus) mac header :skbuff:
__skb_pull(len=234)
skb len=6968 data_len=6968 headroom=0 headlen=0 tailroom=0 end-tail=384 mac=(234,14) mac_len=14 net=(248,40) trans=288shinfo(txflags=0 nr_frags=1 gso(size=1428 type=16 segs=5))csum(0x100120 start=288 offset=16 ip_summed=3 complete_sw=0 valid=1 level=0)hash(0x7b446c6c sw=0 l4=1) proto=0x86dd pkttype=0 iif=60------------[ cut here ]------------ kernel BUG at ./include/linux/skbuff.h:2847!Add
skb_carve_reset_headers()to mark the mac and transport headers as not set, reset the network header, clearskb->mac_len, and drop a now meaninglessCHECKSUM_PARTIAL(csum_startno longer describes anything).Invalidate the inner offsets as well. Unlike
mac_headerandtransport_headerthey have no "unset" sentinel, so a leftover non-zero value still looks like a real header. Zeroskb->inner_mac_header,skb->inner_network_header,skb->inner_transport_header,skb->inner_protocolandskb->encapsulation, so that all the header state is invalidated in one place.v2: fixed an inaccurate changelog. The stale offsets stay inside the
newskb->head, which is never smaller than the old one, they simply point pastskb_tail_pointer()to bytes that are gone. Thanks to Xuanqiang Luo for insisting on this.
Also invalidate the inner header state, as suggested by the netdev AI review :
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260911114922.621937-1-edumazet%40google.com
Quoted 7 lines
Fixes 6fa01ccd8830 ("skbuff: Add pskb_extract() helper function")Reported-by [email protected]Cc Xuanqiang Luo <[email protected]>Cc Allison Henderson <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
Thanks!
[email protected]
AI reviewThank 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
- [Medium] Incomplete invalidation of checksum metadata in the new skb_carve_reset_headers() (net/core/skbuff.c:6842).
--
net: skbuff: do not leave stale header offsets after pskb_carve()
The two pskb_carve() helpers used to call skb_headers_offset_update(skb, 0), which left mac/network/transport offsets describing bytes that were just removed. This patch adds skb_carve_reset_headers() to unset the mac and transport headers, reset the network header, clear mac_len, zero the inner header state, and downgrade CHECKSUM_PARTIAL to CHECKSUM_NONE.
Quoted 25 lines
net/core/skbuff.c +17
-0@@ -6832,6 +6832,34 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, }EXPORT_SYMBOL (alloc_skb_with_frags); +/* pskb_carve_inside_header() and pskb_carve_inside_nonlinear() +* remove the first bytes of a packet and reallocate skb->head. +* +* Whatever headers were present before the operation are gone, +* we must not leave stale offsets, otherwise users of this skb +* (skb_dump(), drop_monitor, taps, ...) would read or pull garbage. +*/ +static void skb_carve_reset_headers (struct sk_buff *skb) +{ +skb_unset_mac_header (skb); +skb_unset_transport_header (skb); +skb_reset_network_header (skb); + skb->mac_len =0 ; + +/* Inner offsets have no "unset" marker, zero them so that +* skb_inner_network_header_was_set() becomes false and no +* consumer mistakes them for a real (and long gone) header.
net/core/skbuff.c struct sk_buff *alloc_skb_with_frags(unsigned long header_len, · line 6861
Quoted 10 lines
net/core/skbuff.c +10
-0+*/ + skb->inner_mac_header =0 ; + skb->inner_network_header =0 ; + skb->inner_transport_header =0 ; + skb->inner_protocol =0 ; + skb->encapsulation =0 ; + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) + skb->ip_summed =CHECKSUM_NONE ; +}
[Severity: Medium]
The changelog says the goal is that "all the header state is invalidated in one place". Is the checksum state fully invalidated here?
skb_carve_reset_headers() only rewrites ip_summed, while skb->csum, skb->csum_valid, skb->csum_complete_sw, skb->csum_level and skb->csum_not_inet keep the values they had before the bytes were removed.
For the CHECKSUM_PARTIAL case, the syzbot dump quoted in the changelog shows the incoming skb already has valid=1:
csum(0x100120 start=288 offset=16 ip_summed=3 complete_sw=0 valid=1 level=0)
After the downgrade this becomes ip_summed=CHECKSUM_NONE with csum_valid still 1, and skb_csum_unnecessary() in include/linux/skbuff.h returns true on csum_valid alone:
static inline int skb_csum_unnecessary(const struct sk_buff *skb)
{
return ((skb->ip_summed == CHECKSUM_UNNECESSARY) ||
skb->csum_valid ||
(skb->ip_summed == CHECKSUM_PARTIAL &&
skb_checksum_start_offset(skb) >= 0));}
Can a consumer of the carved skb then believe the payload was already verified, even though the bytes the checksum covered are gone? A leftover csum_not_inet would similarly still claim CRC32c semantics, and skb_dump() would print the contradictory "ip_summed=0 ... valid=1".
Should csum_valid, csum_complete_sw, csum_level and csum_not_inet be cleared in the same helper?
The CHECKSUM_COMPLETE case looks untouched as well. Unlike skb_pull_rcsum()/skb_postpull_rcsum(), the carve path never subtracts the off bytes removed from the front from skb->csum, and pskb_extract() trims the tail with plain pskb_trim() rather than pskb_trim_rcsum():
net/core/skbuff.c:pskb_extract() {
...
if (pskb_carve(clone, off, gfp) < 0 ||
pskb_trim(clone, to_copy)) {
...}
So a CHECKSUM_COMPLETE skb keeps a whole-packet checksum that no longer matches its contents. Would it make sense to also drop or fix up CHECKSUM_COMPLETE in skb_carve_reset_headers(), or to use pskb_trim_rcsum() in pskb_extract()?
The only in-tree user of pskb_extract() is RDS, which copies the queued data to userspace and never calls a checksum validation helper, so there is no functional failure visible today; the concern is the trust bits left on a generic exported helper.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260915130423.3956471-1-edumazet%40google.com
Paolo Abeni
maintainerQuoted 106 lines · On 9/16/26 15:05, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 0
- [Medium] Incomplete invalidation of checksum metadata in the new
skb_carve_reset_headers()(net/core/skbuff.c:6842).--
net: skbuff: do not leave stale header offsets after
pskb_carve()The two
pskb_carve()helpers used to callskb_headers_offset_update(skb, 0), which left mac/network/transport offsets describing bytes that were just removed. This patch addsskb_carve_reset_headers()to unset the mac and transport headers, reset the network header, clearmac_len, zero the inner header state, and downgradeCHECKSUM_PARTIALtoCHECKSUM_NONE.Quoted 25 lines
net/core/skbuff.c +17
-0@@ -6832,6 +6832,34 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, }EXPORT_SYMBOL (alloc_skb_with_frags); +/* pskb_carve_inside_header() and pskb_carve_inside_nonlinear() +* remove the first bytes of a packet and reallocate skb->head. +* +* Whatever headers were present before the operation are gone, +* we must not leave stale offsets, otherwise users of this skb +* (skb_dump(), drop_monitor, taps, ...) would read or pull garbage. +*/ +static void skb_carve_reset_headers (struct sk_buff *skb) +{ +skb_unset_mac_header (skb); +skb_unset_transport_header (skb); +skb_reset_network_header (skb); + skb->mac_len =0 ; + +/* Inner offsets have no "unset" marker, zero them so that +* skb_inner_network_header_was_set() becomes false and no +* consumer mistakes them for a real (and long gone) header. net/core/skbuff.c struct sk_buff *alloc_skb_with_frags(unsigned long header_len, · line 6861
Quoted 10 lines
net/core/skbuff.c +10
-0+*/ + skb->inner_mac_header =0 ; + skb->inner_network_header =0 ; + skb->inner_transport_header =0 ; + skb->inner_protocol =0 ; + skb->encapsulation =0 ; + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) + skb->ip_summed =CHECKSUM_NONE ; +}[Severity: Medium]
The changelog says the goal is that "all the header state is invalidated in one place". Is the checksum state fully invalidated here?
skb_carve_reset_headers()only rewritesip_summed, whileskb->csum,skb->csum_valid,skb->csum_complete_sw,skb->csum_levelandskb->csum_not_inetkeep the values they had before the bytes were removed.For the
CHECKSUM_PARTIALcase, the syzbot dump quoted in the changelog shows the incoming skb already has valid=1:csum(0x100120 start=288 offset=16 ip_summed=3 complete_sw=0 valid=1 level=0)After the downgrade this becomes ip_summed=CHECKSUM_NONE with
csum_validstill 1, andskb_csum_unnecessary()ininclude/linux/skbuff.hreturns true oncsum_validalone:static inline int skb_csum_unnecessary(const struct sk_buff *skb) { return ((skb->ip_summed == CHECKSUM_UNNECESSARY) || skb->csum_valid || (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_start_offset(skb) >= 0)); }Can a consumer of the carved skb then believe the payload was already verified, even though the bytes the checksum covered are gone? A leftover
csum_not_inetwould similarly still claim CRC32c semantics, andskb_dump()would print the contradictory "ip_summed=0 ... valid=1".Should
csum_valid,csum_complete_sw,csum_levelandcsum_not_inetbe cleared in the same helper?The
CHECKSUM_COMPLETEcase looks untouched as well. Unlike skb_pull_rcsum()/skb_postpull_rcsum(), the carve path never subtracts the off bytes removed from the front fromskb->csum, andpskb_extract()trims the tail with plainpskb_trim()rather thanpskb_trim_rcsum():net/core/skbuff.c:pskb_extract() { ... if (pskb_carve(clone, off, gfp) < 0 || pskb_trim(clone, to_copy)) { ... }So a
CHECKSUM_COMPLETEskb keeps a whole-packet checksum that no longer matches its contents. Would it make sense to also drop or fix upCHECKSUM_COMPLETEinskb_carve_reset_headers(), or to usepskb_trim_rcsum()inpskb_extract()?
Quoted 4 lines
The only in-tree user of
pskb_extract()is RDS, which copies the queued data to userspace and never calls a checksum validation helper, so there is no functional failure visible today; the concern is the trust bits left on a generic exported helper.
Given the last paragraph all the above is IMHO material for eventual future cleanups.
/P
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Tue, 15 Sep 2026 13:04:23 +0000 you wrote:
pskb_carve_inside_header()andpskb_carve_inside_nonlinear()remove the first bytes of a packet and reallocateskb->head.All the headers that were present before the operation are gone, but both functions call
skb_headers_offset_update(skb, 0), which is a no-op :skb->mac_header,skb->network_header,skb->transport_headerandskb->csum_startkeep their old values and now describe bytes which are no longer there.[...]
Here is the summary with links:
- [v2,net] net: skbuff: do not leave stale header offsets after pskb_carve()
https://git.kernel.org/netdev/net/c/a5117e1eccac
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html