* [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG
@ 2026-11-13 0:21 Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member Josef Bacik
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Josef Bacik @ 2026-11-13 0:21 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev, Josef Bacik
Hello,
Sashiko's review of "net: skbuff: don't run off frag_list in
skb_segment()"[1] found two problems in the branch of skb_segment() that
clones a frag_list member. Both only show without SG. That series was
applied before I got to them, so these go on top.
Patch 1 is about a member that has a frag_list of its own. The clone
loses the nested data and the next member goes out in its place. My
patch made this worse: for some layouts it turned a NULL pointer
dereference into wrong data. Nothing in the tree is known to build such
an skb.
Patch 2 is older and doesn't need a broken skb. Without SG the copy
doesn't move the frag_list walk along, so a member that has already been
copied from can still be cloned.
Patch 3 makes the GSO KUnit test compare the payload of the segments.
It only looked at their lengths, which is how I missed the first problem.
Patch 4 adds the layouts that went wrong.
GSO_BY_FRAGS is left exactly as it is. It needs a fix of its own, which
I'll send separately.
The bug that patch 2 fixes is in released kernels. Both fixes change
the condition as that series left it, which is only in net-next, so I've
based all of this on net-next.
I tested this with the net_core KUnit tests at each patch, with each
check taken out in turn to see a case fail, and with a throwaway KUnit
case that segments 100000 random layouts and compares the payload.
Without SG, out of 10000 layouts each:
wrong payload -EINVAL right
nested, net-next 61 78 9861
nested, patch 1 0 0 10000
valid, net-next 79 39 9882
valid, patch 2 0 0 10000
The results with SG, and with GSO_BY_FRAGS with and without SG, are the
same before and after each patch. I also ran SCTP over veth with
tx-sctp-segmentation off, and the tests from the earlier series under
KASAN. Thanks,
Josef
[1] https://lore.kernel.org/all/20261104-b4-skbuff-bug-on-followups-v4-11-b7ffeb364f5d@toxicpanda.com/
---
Josef Bacik (4):
net: skbuff: don't clone a nested frag_list member
net: skbuff: don't clone a stale frag_list member
net: compare the payload in the GSO KUnit test
net: test more frag_list layouts without SG
net/core/net_test.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++-----
net/core/skbuff.c | 12 +++-
2 files changed, 190 insertions(+), 21 deletions(-)
---
base-commit: 676f3aace662fbbc180b3898b190a372fa2a516b
change-id: 20261112-b4-skb-segment-clone-fixes-79ddc7ec0494
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member
2026-11-13 0:21 [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG Josef Bacik
@ 2026-11-13 0:21 ` Josef Bacik
2026-11-19 9:23 ` Paolo Abeni
2026-11-13 0:21 ` [PATCH net-next 2/4] net: skbuff: don't clone a stale " Josef Bacik
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Josef Bacik @ 2026-11-13 0:21 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev, Josef Bacik
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 <josef@toxicpanda.com>
---
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/4] net: skbuff: don't clone a stale frag_list member
2026-11-13 0:21 [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member Josef Bacik
@ 2026-11-13 0:21 ` Josef Bacik
2026-11-19 9:26 ` Paolo Abeni
2026-11-13 0:21 ` [PATCH net-next 3/4] net: compare the payload in the GSO KUnit test Josef Bacik
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Josef Bacik @ 2026-11-13 0:21 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev, Josef Bacik
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 <josef@toxicpanda.com>
---
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 3/4] net: compare the payload in the GSO KUnit test
2026-11-13 0:21 [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 2/4] net: skbuff: don't clone a stale " Josef Bacik
@ 2026-11-13 0:21 ` Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 4/4] net: test more frag_list layouts without SG Josef Bacik
2026-11-13 2:52 ` [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists " Mina Almasry
4 siblings, 0 replies; 8+ messages in thread
From: Josef Bacik @ 2026-11-13 0:21 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev, Josef Bacik
The GSO KUnit test only compares the lengths of the segments, so it
passes if skb_segment() puts the wrong data into a segment of the right
length.
Fill the skb with bytes that depend on their place in the payload, and
compare the payload of the segments with that pattern. Also check that
the segments add up to the whole payload.
Turn the assertions on the segments into expectations. A failed
assertion ends the test at once and leaks the skb and the segments that
are left.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
net/core/net_test.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 51 insertions(+), 7 deletions(-)
diff --git a/net/core/net_test.c b/net/core/net_test.c
index 976d14896251..6a1aebac5874 100644
--- a/net/core/net_test.c
+++ b/net/core/net_test.c
@@ -372,12 +372,26 @@ static void gso_test_case_to_desc(struct gso_test_case *t, char *desc)
KUNIT_ARRAY_PARAM(gso_test, cases, gso_test_case_to_desc);
+/* Each byte depends on its place in the payload, so that data from the wrong
+ * offset of the right piece doesn't compare equal. 251 is prime, so the
+ * pattern doesn't repeat in step with GSO_TEST_SIZE.
+ */
+static void gso_test_fill(void *data, unsigned int len, unsigned int *pos)
+{
+ u8 *p = data;
+
+ while (len--)
+ *p++ = (*pos)++ % 251;
+}
+
static void gso_test_func(struct kunit *test)
{
const int shinfo_size = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
struct sk_buff *skb, *segs, *cur, *next, *last;
+ unsigned int payload_len, fill = 0, off = 0;
const struct gso_test_case *tcase;
netdev_features_t features;
+ u8 *payload, *seg_payload;
struct page *page;
int i;
@@ -394,6 +408,7 @@ static void gso_test_func(struct kunit *test)
__skb_put(skb, sizeof(hdr) + tcase->linear_len);
__init_skb(skb);
+ gso_test_fill(skb->data, tcase->linear_len, &fill);
skb_shinfo(skb)->gso_type = tcase->gso_type;
if (tcase->nr_frags) {
@@ -409,6 +424,7 @@ static void gso_test_func(struct kunit *test)
}
KUNIT_ASSERT_LE(test, pg_off, PAGE_SIZE);
+ gso_test_fill(page_address(page), pg_off, &fill);
skb->data_len = pg_off;
skb->len += skb->data_len;
@@ -432,13 +448,16 @@ static void gso_test_func(struct kunit *test)
frag_size + shinfo_size);
}
KUNIT_ASSERT_NOT_NULL(test, frag_skb);
- __skb_put(frag_skb, frag_size);
+ gso_test_fill(__skb_put(frag_skb, frag_size), frag_size,
+ &fill);
frag_len = tcase->frag_skb_frags ? tcase->frag_skb_frags[i] : 0;
if (frag_len) {
+ KUNIT_ASSERT_LE(test, frag_len, PAGE_SIZE);
page = alloc_page(GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, page);
skb_fill_page_desc(frag_skb, 0, page, 0, frag_len);
+ gso_test_fill(page_address(page), frag_len, &fill);
frag_skb->data_len = frag_len;
frag_skb->len += frag_len;
@@ -502,6 +521,18 @@ static void gso_test_func(struct kunit *test)
goto free_gso_skb;
}
+ /* the segments have to hold the bytes of the fill, in its order */
+ payload_len = skb->len;
+ KUNIT_EXPECT_EQ(test, fill, payload_len);
+ payload = kunit_kmalloc(test, payload_len, GFP_KERNEL);
+ seg_payload = kunit_kmalloc(test, payload_len, GFP_KERNEL);
+ if (!payload || !seg_payload) {
+ KUNIT_FAIL(test, "no memory for the payload");
+ goto free_gso_skb;
+ }
+ fill = 0;
+ gso_test_fill(payload, payload_len, &fill);
+
segs = skb_segment(skb, features);
if (IS_ERR(segs)) {
KUNIT_FAIL(test, "segs error %pe", segs);
@@ -518,14 +549,26 @@ static void gso_test_func(struct kunit *test)
if (i >= tcase->nr_segs)
goto consume;
- KUNIT_ASSERT_EQ(test, cur->len, sizeof(hdr) + tcase->segs[i]);
+ KUNIT_EXPECT_EQ(test, cur->len, sizeof(hdr) + tcase->segs[i]);
/* segs have skb->data pointing to the mac header */
- KUNIT_ASSERT_PTR_EQ(test, skb_mac_header(cur), cur->data);
- KUNIT_ASSERT_PTR_EQ(test, skb_network_header(cur), cur->data + sizeof(hdr));
+ KUNIT_EXPECT_PTR_EQ(test, skb_mac_header(cur), cur->data);
+ KUNIT_EXPECT_PTR_EQ(test, skb_network_header(cur), cur->data + sizeof(hdr));
/* header was copied to all segs */
- KUNIT_ASSERT_EQ(test, memcmp(skb_mac_header(cur), hdr, sizeof(hdr)), 0);
+ KUNIT_EXPECT_EQ(test, memcmp(skb_mac_header(cur), hdr, sizeof(hdr)), 0);
+
+ if (off + tcase->segs[i] > payload_len ||
+ skb_copy_bits(cur, sizeof(hdr), seg_payload,
+ tcase->segs[i])) {
+ KUNIT_FAIL(test, "can't copy segment %d", i);
+ kfree_skb_list(cur);
+ goto free_gso_skb;
+ }
+ KUNIT_EXPECT_MEMEQ(test, seg_payload, payload + off,
+ tcase->segs[i]);
+ off += tcase->segs[i];
+
if (tcase->gso_segs) {
unsigned int gso_segs = tcase->gso_segs[i];
@@ -542,13 +585,14 @@ static void gso_test_func(struct kunit *test)
/* last seg can be found through segs->prev pointer */
if (!next)
- KUNIT_ASSERT_PTR_EQ(test, cur, last);
+ KUNIT_EXPECT_PTR_EQ(test, cur, last);
consume:
consume_skb(cur);
}
- KUNIT_ASSERT_EQ(test, i, tcase->nr_segs);
+ KUNIT_EXPECT_EQ(test, off, payload_len);
+ KUNIT_EXPECT_EQ(test, i, tcase->nr_segs);
free_gso_skb:
consume_skb(skb);
--
2.55.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 4/4] net: test more frag_list layouts without SG
2026-11-13 0:21 [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG Josef Bacik
` (2 preceding siblings ...)
2026-11-13 0:21 ` [PATCH net-next 3/4] net: compare the payload in the GSO KUnit test Josef Bacik
@ 2026-11-13 0:21 ` Josef Bacik
2026-11-13 2:52 ` [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists " Mina Almasry
4 siblings, 0 replies; 8+ messages in thread
From: Josef Bacik @ 2026-11-13 0:21 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev, Josef Bacik
Add layouts that skb_segment() got wrong without SG, which have to be
segmented now.
For "net: skbuff: don't clone a nested frag_list member":
- A nested frag_list with one more member after it.
- The same with a last member that is never cloned, so that the walk
doesn't run out of members.
- A nested member that is shorter than a segment. It was never cloned,
so this case passes without the fix too.
For "net: skbuff: don't clone a stale frag_list member", three layouts
where a member that has been copied from is as long as a later segment.
That patch leaves GSO_BY_FRAGS alone. Add a GSO_BY_FRAGS layout with
data pulled into the head, which fails with -EINVAL before and after.
It would be cut in the wrong places if GSO_BY_FRAGS took the new test.
Two fields say which cases nest the second member and which use
GSO_BY_FRAGS, instead of a test for each id.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
net/core/net_test.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 129 insertions(+), 12 deletions(-)
diff --git a/net/core/net_test.c b/net/core/net_test.c
index 6a1aebac5874..19a12e1c048a 100644
--- a/net/core/net_test.c
+++ b/net/core/net_test.c
@@ -48,6 +48,13 @@ enum gso_test_nr {
GSO_TEST_SHORT_FRAG_LIST,
GSO_TEST_SHORT_GSO_BY_FRAGS,
GSO_TEST_FRAG_LIST_NESTED_NO_SG,
+ GSO_TEST_FRAG_LIST_NESTED_NEXT_NO_SG,
+ GSO_TEST_FRAG_LIST_NESTED_TAIL_NO_SG,
+ GSO_TEST_FRAG_LIST_NESTED_COPY_NO_SG,
+ GSO_TEST_FRAG_LIST_STALE_TAIL_NO_SG,
+ GSO_TEST_FRAG_LIST_STALE_HEAD_NO_SG,
+ GSO_TEST_FRAG_LIST_STALE_FRAGS_NO_SG,
+ GSO_TEST_GSO_BY_FRAGS_PULLED_NO_SG,
GSO_TEST_SHORT_LINEAR_NO_SG,
GSO_TEST_SHORT_LINEAR_STRADDLE_NO_SG,
GSO_TEST_SHORT_FRAG_LIST_NO_SG,
@@ -73,6 +80,12 @@ struct gso_test_case {
unsigned int missing_len;
/* segment without NETIF_F_SG */
bool no_sg;
+ /* the second frag_list member hangs off the first one's frag_list
+ * instead of off the head's
+ */
+ bool nested;
+ /* gso_size is GSO_BY_FRAGS */
+ bool by_frags;
/* output as expected */
unsigned int nr_segs;
@@ -192,6 +205,7 @@ static struct gso_test_case cases[] = {
*/
.id = GSO_TEST_GSO_BY_FRAGS,
.name = "gso_by_frags",
+ .by_frags = true,
.nr_frag_skbs = 4,
.frag_skbs = (const unsigned int[]) { 100, 200, 300, 400 },
.nr_segs = 4,
@@ -271,11 +285,9 @@ static struct gso_test_case cases[] = {
.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",
+ .nested = true,
.linear_len = GSO_TEST_SIZE,
.nr_frag_skbs = 2,
.frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE },
@@ -309,6 +321,7 @@ static struct gso_test_case cases[] = {
{
.id = GSO_TEST_SHORT_GSO_BY_FRAGS,
.name = "short_gso_by_frags",
+ .by_frags = true,
.nr_frag_skbs = 2,
.frag_skbs = (const unsigned int[]) { 100, 200 },
.missing_len = 50,
@@ -320,6 +333,7 @@ static struct gso_test_case cases[] = {
*/
.id = GSO_TEST_FRAG_LIST_NESTED_NO_SG,
.name = "frag_list_nested_no_sg",
+ .nested = true,
.linear_len = GSO_TEST_SIZE,
.nr_frag_skbs = 2,
.frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE },
@@ -327,6 +341,109 @@ static struct gso_test_case cases[] = {
.nr_segs = 3,
.segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE, GSO_TEST_SIZE },
},
+ {
+ /* a clone of the first member would lose the nested data, and
+ * the third member would go out in its place
+ */
+ .id = GSO_TEST_FRAG_LIST_NESTED_NEXT_NO_SG,
+ .name = "frag_list_nested_next_no_sg",
+ .nested = true,
+ .linear_len = GSO_TEST_SIZE,
+ .nr_frag_skbs = 3,
+ .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE,
+ GSO_TEST_SIZE },
+ .no_sg = true,
+ .nr_segs = 4,
+ .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE,
+ GSO_TEST_SIZE, GSO_TEST_SIZE },
+ },
+ {
+ /* the same, but the last member is never cloned, so the walk
+ * doesn't run out of members either
+ */
+ .id = GSO_TEST_FRAG_LIST_NESTED_TAIL_NO_SG,
+ .name = "frag_list_nested_tail_no_sg",
+ .nested = true,
+ .linear_len = GSO_TEST_SIZE,
+ .nr_frag_skbs = 4,
+ .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE,
+ GSO_TEST_SIZE, 200 },
+ .frag_skb_frags = (const unsigned int[]) { 0, 0, 0, 100 },
+ .no_sg = true,
+ .nr_segs = 5,
+ .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE,
+ GSO_TEST_SIZE, GSO_TEST_SIZE, 300 },
+ },
+ {
+ /* the nested member is shorter than a segment, so it was never
+ * cloned
+ */
+ .id = GSO_TEST_FRAG_LIST_NESTED_COPY_NO_SG,
+ .name = "frag_list_nested_copy_no_sg",
+ .nested = true,
+ .linear_len = GSO_TEST_SIZE,
+ .nr_frag_skbs = 3,
+ .frag_skbs = (const unsigned int[]) { 500, 500, GSO_TEST_SIZE },
+ .no_sg = true,
+ .nr_segs = 3,
+ .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE, GSO_TEST_SIZE },
+ },
+ {
+ /* the copy doesn't move the walk past the 3 byte member, which
+ * then is as long as the last segment
+ */
+ .id = GSO_TEST_FRAG_LIST_STALE_TAIL_NO_SG,
+ .name = "frag_list_stale_tail_no_sg",
+ .linear_len = GSO_TEST_SIZE,
+ .nr_frag_skbs = 3,
+ .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, 3, GSO_TEST_SIZE },
+ .no_sg = true,
+ .nr_segs = 4,
+ .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE, GSO_TEST_SIZE, 3 },
+ },
+ {
+ /* half of the first member is copied along with the end of the
+ * head, and the member is as long as the next segment
+ */
+ .id = GSO_TEST_FRAG_LIST_STALE_HEAD_NO_SG,
+ .name = "frag_list_stale_head_no_sg",
+ .linear_len = 2 * GSO_TEST_SIZE + 500,
+ .nr_frag_skbs = 2,
+ .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE, 500 },
+ .no_sg = true,
+ .nr_segs = 4,
+ .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE,
+ GSO_TEST_SIZE, GSO_TEST_SIZE },
+ },
+ {
+ /* the same with a frag on the member, which used to get its
+ * first bytes sent twice instead of an error
+ */
+ .id = GSO_TEST_FRAG_LIST_STALE_FRAGS_NO_SG,
+ .name = "frag_list_stale_frags_no_sg",
+ .linear_len = 500,
+ .nr_frag_skbs = 1,
+ .frag_skbs = (const unsigned int[]) { GSO_TEST_SIZE },
+ .frag_skb_frags = (const unsigned int[]) { 700 },
+ .no_sg = true,
+ .nr_segs = 3,
+ .segs = (const unsigned int[]) { GSO_TEST_SIZE, GSO_TEST_SIZE, 200 },
+ },
+ {
+ /* 16 bytes of the first member were pulled into the head. The
+ * lengths come from a stale member too, and the first one
+ * divides the total, so this must not start to succeed with
+ * three segments of 1000 bytes.
+ */
+ .id = GSO_TEST_GSO_BY_FRAGS_PULLED_NO_SG,
+ .name = "gso_by_frags_pulled_no_sg",
+ .by_frags = true,
+ .linear_len = 16,
+ .nr_frag_skbs = 3,
+ .frag_skbs = (const unsigned int[]) { 1000, 1016, 968 },
+ .no_sg = true,
+ .err = -EINVAL,
+ },
{
/* without SG it is skb_copy_bits() that runs out of data */
.id = GSO_TEST_SHORT_LINEAR_NO_SG,
@@ -357,6 +474,7 @@ static struct gso_test_case cases[] = {
{
.id = GSO_TEST_SHORT_GSO_BY_FRAGS_NO_SG,
.name = "short_gso_by_frags_no_sg",
+ .by_frags = true,
.nr_frag_skbs = 2,
.frag_skbs = (const unsigned int[]) { 100, 200 },
.missing_len = 50,
@@ -478,19 +596,18 @@ static void gso_test_func(struct kunit *test)
skb->data_len += total_size;
skb->truesize += total_true_size;
- if (tcase->id == GSO_TEST_GSO_BY_FRAGS ||
- tcase->id == GSO_TEST_SHORT_GSO_BY_FRAGS ||
- tcase->id == GSO_TEST_SHORT_GSO_BY_FRAGS_NO_SG)
+ if (tcase->by_frags)
skb_shinfo(skb)->gso_size = GSO_BY_FRAGS;
- if (tcase->id == GSO_TEST_FRAG_LIST_NESTED ||
- tcase->id == GSO_TEST_FRAG_LIST_NESTED_NO_SG) {
+ if (tcase->nested) {
struct sk_buff *first = skb_shinfo(skb)->frag_list;
+ struct sk_buff *second = first->next;
- skb_shinfo(first)->frag_list = first->next;
- first->next = NULL;
- first->len += tcase->frag_skbs[1];
- first->data_len += tcase->frag_skbs[1];
+ first->next = second->next;
+ second->next = NULL;
+ skb_shinfo(first)->frag_list = second;
+ first->len += second->len;
+ first->data_len += second->len;
}
}
--
2.55.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG
2026-11-13 0:21 [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG Josef Bacik
` (3 preceding siblings ...)
2026-11-13 0:21 ` [PATCH net-next 4/4] net: test more frag_list layouts without SG Josef Bacik
@ 2026-11-13 2:52 ` Mina Almasry
4 siblings, 0 replies; 8+ messages in thread
From: Mina Almasry @ 2026-11-13 2:52 UTC (permalink / raw)
To: Josef Bacik
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Andrew Lunn, Willem de Bruijn,
Fernando Fernandez Mancera, David Laight, netdev
On Thu, Nov 12, 2026 at 4:21 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> Hello,
>
> Sashiko's review of "net: skbuff: don't run off frag_list in
> skb_segment()"[1] found two problems in the branch of skb_segment() that
> clones a frag_list member. Both only show without SG. That series was
> applied before I got to them, so these go on top.
>
> Patch 1 is about a member that has a frag_list of its own. The clone
> loses the nested data and the next member goes out in its place. My
> patch made this worse: for some layouts it turned a NULL pointer
> dereference into wrong data. Nothing in the tree is known to build such
> an skb.
>
> Patch 2 is older and doesn't need a broken skb. Without SG the copy
> doesn't move the frag_list walk along, so a member that has already been
> copied from can still be cloned.
>
> Patch 3 makes the GSO KUnit test compare the payload of the segments.
> It only looked at their lengths, which is how I missed the first problem.
> Patch 4 adds the layouts that went wrong.
>
> GSO_BY_FRAGS is left exactly as it is. It needs a fix of its own, which
> I'll send separately.
>
> The bug that patch 2 fixes is in released kernels. Both fixes change
> the condition as that series left it, which is only in net-next, so I've
> based all of this on net-next.
>
> I tested this with the net_core KUnit tests at each patch, with each
> check taken out in turn to see a case fail, and with a throwaway KUnit
> case that segments 100000 random layouts and compares the payload.
> Without SG, out of 10000 layouts each:
>
> wrong payload -EINVAL right
> nested, net-next 61 78 9861
> nested, patch 1 0 0 10000
> valid, net-next 79 39 9882
> valid, patch 2 0 0 10000
>
> The results with SG, and with GSO_BY_FRAGS with and without SG, are the
> same before and after each patch. I also ran SCTP over veth with
> tx-sctp-segmentation off, and the tests from the earlier series under
> KASAN. Thanks,
>
> Josef
>
> [1] https://lore.kernel.org/all/20261104-b4-skbuff-bug-on-followups-v4-11-b7ffeb364f5d@toxicpanda.com/
>
> ---
> Josef Bacik (4):
> net: skbuff: don't clone a nested frag_list member
> net: skbuff: don't clone a stale frag_list member
> net: compare the payload in the GSO KUnit test
> net: test more frag_list layouts without SG
>
> net/core/net_test.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++-----
> net/core/skbuff.c | 12 +++-
> 2 files changed, 190 insertions(+), 21 deletions(-)
> ---
> base-commit: 676f3aace662fbbc180b3898b190a372fa2a516b
> change-id: 20261112-b4-skb-segment-clone-fixes-79ddc7ec0494
>
Reviewed-by: Mina Almasry <almasrymina@google.com>
--
Thanks,
Mina
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member
2026-11-13 0:21 ` [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member Josef Bacik
@ 2026-11-19 9:23 ` Paolo Abeni
0 siblings, 0 replies; 8+ messages in thread
From: Paolo Abeni @ 2026-11-19 9:23 UTC (permalink / raw)
To: Josef Bacik, David S. Miller, Eric Dumazet, Jakub Kicinski,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev
On 11/13/26 01:21, Josef Bacik wrote:
> 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.
If nothing builds the problematic layout, this feels like defensive
programming, and we should avoid it.
/P
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 2/4] net: skbuff: don't clone a stale frag_list member
2026-11-13 0:21 ` [PATCH net-next 2/4] net: skbuff: don't clone a stale " Josef Bacik
@ 2026-11-19 9:26 ` Paolo Abeni
0 siblings, 0 replies; 8+ messages in thread
From: Paolo Abeni @ 2026-11-19 9:26 UTC (permalink / raw)
To: Josef Bacik, David S. Miller, Eric Dumazet, Jakub Kicinski,
Simon Horman, Andrew Lunn
Cc: Willem de Bruijn, Fernando Fernandez Mancera, Mina Almasry,
David Laight, netdev
On 11/13/26 01:21, Josef Bacik wrote:
> 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.
I must admit the problematic layout is not clear to me, nor if there is
anything build such skbs in the kernel.
Could you please clarify? Note that in the latter case I think we should
drop even this patch.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-19 9:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 0:21 [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists without SG Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 1/4] net: skbuff: don't clone a nested frag_list member Josef Bacik
2026-11-19 9:23 ` Paolo Abeni
2026-11-13 0:21 ` [PATCH net-next 2/4] net: skbuff: don't clone a stale " Josef Bacik
2026-11-19 9:26 ` Paolo Abeni
2026-11-13 0:21 ` [PATCH net-next 3/4] net: compare the payload in the GSO KUnit test Josef Bacik
2026-11-13 0:21 ` [PATCH net-next 4/4] net: test more frag_list layouts without SG Josef Bacik
2026-11-13 2:52 ` [PATCH net-next 0/4] net: skbuff: skb_segment() fixes for frag_lists " Mina Almasry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox