A reassembled skb keeps the head fragment's unreadable bit while chaining subsequent fragments onto frag_list. Upper-layer socket receive paths dispatch based on skb_frags_readable() of the head skb (for example, tcp_recvmsg_locked() routes to skb_copy_datagram_msg() vs. tcp_recvmsg_dmabuf()), and require uniform readability across all frag_list entries. Mixing readable and unreadable fragments in the same reassembly queue (for example, when fragments split across a devmem queue and a normal queue, or when a size-threshold spill places only larger fragments in unreadable netmem) produces a mixed-readability reassembled skb that fails on delivery with -EFAULT or -ENODEV. Reject a fragment in inet_frag_queue_insert() when its readability differs from the fragments already in the queue, mirroring IPFRAG_MIXED_SECPATH, while continuing to allow uniformly unreadable fragments to reassemble. Also propagate head->unreadable to the wrapper skb allocated by inet_frag_reasm_prepare() when the first fragment already carries a frag_list. This issue was found by code inspection while developing per-socket devmem RX and reproduced and verified with the accompanying net_test KUnit tests. Fixes: 65249feb6b3d ("net: add support for skbs with unreadable frags") Assisted-by: LLM Signed-off-by: Octavian Purdila --- include/net/inet_frag.h | 1 + net/ipv4/inet_fragment.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h index c1fb419a9cf03..668cb042b36b3 100644 --- a/include/net/inet_frag.h +++ b/include/net/inet_frag.h @@ -175,6 +175,7 @@ extern const u8 ip_frag_ecn_table[16]; #define IPFRAG_OVERLAP 2 #define IPFRAG_MIXED_SECPATH 3 #define IPFRAG_TOOBIG 4 +#define IPFRAG_MIXED_READABILITY 5 /* Max sum of the truesize of fragments in a queue. This keeps the sums * done in inet_frag_reasm_prepare() and inet_frag_reasm_finish() well diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c index f330d0a398233..caf07cf1a411c 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c @@ -444,9 +444,15 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, { struct sk_buff *last = q->fragments_tail; - /* The reassembled skb keeps the first fragment's secpath. */ - if (last && !secpath_equal(last, skb)) - return IPFRAG_MIXED_SECPATH; + /* The reassembled skb keeps the first fragment's secpath and + * readability state. + */ + if (last) { + if (!secpath_equal(last, skb)) + return IPFRAG_MIXED_SECPATH; + if (skb_frags_readable(last) != skb_frags_readable(skb)) + return IPFRAG_MIXED_READABILITY; + } if (skb->truesize > INET_FRAG_MAX_TRUESIZE - q->truesize) return IPFRAG_TOOBIG; @@ -639,6 +645,7 @@ void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb, head->truesize += clone->truesize; clone->csum = 0; clone->ip_summed = head->ip_summed; + clone->unreadable = head->unreadable; add_frag_mem_limit(q->fqdir, clone->truesize); skb_shinfo(head)->frag_list = clone; nextp = &clone->next; -- 2.56.1.915.g69d5ec7298-goog