skb_segment() clones a frag_list member whose linear part fills the segment. pskb_trim() drops a nested frag_list from the clone, and the walk moves on to the next member while head_skb->len still counts the nested bytes. With SG the walk then runs out of members and the segmentation fails. Without SG the segments that aren't clones are copied out of head_skb by offset, so the nested bytes are dropped and a later member goes out twice. Take a gso_size of 1000, a head of 1000 bytes, a member A of 1000 bytes with a nested frag_list of 1000, a member B of 1000 bytes, and a member C with 200 linear bytes and a frag of 100. The segments come out as head, A, B, B, C. Without C this was a NULL pointer dereference before commit e447e46ce976 ("net: skbuff: don't run off frag_list in skb_segment()"), and B goes out twice since then. Don't clone a member that has a frag_list. Without SG the segment is then copied by offset, and the copy recurses into the nested frag_list. With SG the segmentation still fails with -EINVAL. Nothing in the tree is known to build such an skb. Found by the Sashiko AI review of that commit. Fixes: dbd50f238dec ("net: move the hsize check to the else block in skb_segment") Fixes: e447e46ce976 ("net: skbuff: don't run off frag_list in skb_segment()") Link: https://sashiko.dev/#/patchset/20261104-b4-skbuff-bug-on-followups-v4-0-b7ffeb364f5d%40toxicpanda.com Signed-off-by: Josef Bacik --- net/core/skbuff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 457d57d49fc0..7c232c5c8883 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5247,8 +5247,9 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, hsize = skb_headlen(head_skb) - offset; + /* pskb_trim() would drop a nested frag_list from the clone */ if (hsize <= 0 && i >= nfrags && list_skb && - skb_headlen(list_skb) && + skb_headlen(list_skb) && !skb_has_frag_list(list_skb) && (skb_headlen(list_skb) == len || sg)) { if (unlikely(skb_headlen(list_skb) > len)) { DEBUG_NET_WARN_ON_ONCE(1); -- 2.55.0