Without SG, skb_segment() copies a segment out of head_skb by offset and doesn't move pos, i or list_skb along. It still clones list_skb if its linear part is as long as a later segment, although part or all of that member has been copied already. This doesn't take a broken skb. Take a gso_size of 1000, a head of 500 bytes and one member with 1000 linear bytes and a frag of 700. The second segment is a clone that starts at the member's first byte again. With a head of 2500 bytes and members of 1000 and 500 bytes, the segmentation fails with -EINVAL instead. Only clone list_skb if pos == offset, which says that the walk is where the segment starts. With SG that always holds once i >= nfrags, so nothing changes there. GSO_BY_FRAGS is left as it is. It also takes the length of each segment from list_skb, so this test alone would turn a segmentation that fails today into one with the wrong boundaries. That needs a fix of its own. Found by the Sashiko AI review of commit e447e46ce976 ("net: skbuff: don't run off frag_list in skb_segment()"). Fixes: dbd50f238dec ("net: move the hsize check to the else block 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 7c232c5c8883..f63946604674 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5247,10 +5247,17 @@ 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 */ + /* pskb_trim() would drop a nested frag_list from the clone. + * Without SG the copy below doesn't move the walk along, so a + * copy that reads past pos leaves pos behind offset for good, + * and list_skb is then stale. GSO_BY_FRAGS takes its lengths + * from list_skb too, so that test alone wouldn't help it, and + * it is left as it is. + */ if (hsize <= 0 && i >= nfrags && list_skb && skb_headlen(list_skb) && !skb_has_frag_list(list_skb) && - (skb_headlen(list_skb) == len || sg)) { + (skb_headlen(list_skb) == len || sg) && + (pos == offset || gso_by_frags)) { if (unlikely(skb_headlen(list_skb) > len)) { DEBUG_NET_WARN_ON_ONCE(1); err = -EINVAL; -- 2.55.0