tls: fix RX desync on overlapping skbs
Subsystems (3)
PATCH v2 1/1 tls: fix RX desync on overlapping skbs
The TCP receive queue can hold adjacent skbs whose sequence ranges overlap. The tls fast-path reads the record header with skb_copy_bits() by byte offset, which assumes skbs do not overlap, so a header split across the overlap is misread and the connection aborts (-EMSGSIZE/-EINVAL). tls_strp_check_queue_ok() detects such overlaps but only ran after the header was parsed, never covering the header itself.
Observed with parallel kTLS connections on:
- ConnectX-7 + IPsec crypto offload + GRO
- VirtIO (8 queues) + GRO
---
v2:
- move the stm.offset addition into tls_strp_check_queue_ok() No functional change from v1
Tested on Linux kernel 7.2-rc6
--- net/tls/tls_strp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
net/tls/tls_strp.c +11 -5
@@ -430,9 +430,10 @@ static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort)return 0 ; } -static bool tls_strp_check_queue_ok (struct tls_strparser *strp) +static bool tls_strp_check_queue_ok (struct tls_strparser *strp, +unsigned int len) { -unsigned int len = strp->stm.offset + strp->stm.full_len; +unsigned int remaining = strp->stm.offset + len;struct sk_buff *first, *skb;u32 seq;
@@ -443,9 +444,9 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp)/* Make sure there's no duplicate data in the queue, * and the decrypted status matches. */ -while (skb->len < len) { +while (skb->len < remaining) { seq += skb->len; - len -= skb->len; + remaining -= skb->len; skb = skb->next;if (TCP_SKB_CB (skb)->seq != seq)
@@ -525,6 +526,11 @@ static int tls_strp_read_sock(struct tls_strparser *strp)tls_strp_load_anchor_with_queue (strp, inq);if (!strp->stm.full_len) { +if (inq <TLS_HEADER_SIZE ) +return tls_strp_read_copy (strp, true); +if (!tls_strp_check_queue_ok (strp,TLS_HEADER_SIZE )) +return tls_strp_read_copy (strp, false); + sz =tls_rx_msg_size (strp, strp->anchor);if (sz <0 )return sz;
@@ -535,7 +541,7 @@ static int tls_strp_read_sock(struct tls_strparser *strp)return tls_strp_read_copy (strp, true); } -if (!tls_strp_check_queue_ok (strp)) +if (!tls_strp_check_queue_ok (strp, strp->stm.full_len))return tls_strp_read_copy (strp, false);WRITE_ONCE (strp->msg_ready,1 );
Signature · 1 line
2.55.0
I just saw that for the v2 of this patch sashiko reported a supposed potential null dereference which I believe to be an erroneous finding.
Sashiko claims that in tls_strp_check_queue_ok() after first = skb_shinfo(strp->anchor)->frag_list; first may be NULL which would result in a null dereference on seq = TCP_SKB_CB(first)->seq;
tls_strp_check_queue_ok(strp, TLS_HEADER_SIZE) is only called if inq >= TLS_HEADER_SIZE. tcp_inq() counts real payload bytes so [copied_seq, rcv_nxt) holds at least TLS_HEADER_SIZE bytes which live in sk-
Quoted 1 line
sk_receive_queue.tcp_recv_skb(sk, copied_seq)returns the skb
covering copied_seq. tls_strp_load_anchor_with_queue() stores it in anchor->frag_list.
Therefore, skb_shinfo(strp->anchor)->frag_list != NULL for the check introduced by this patch.
Kind regards,
Max Brandtner
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Thu, 13 Aug 2026 14:09:44 +0200 you wrote:
The TCP receive queue can hold adjacent skbs whose sequence ranges overlap. The tls fast-path reads the record header with
skb_copy_bits()by byte offset, which assumes skbs do not overlap, so a header split across the overlap is misread and the connection aborts (-EMSGSIZE/-EINVAL).tls_strp_check_queue_ok()detects such overlaps but only ran after the header was parsed, never covering the header itself.[...]
Here is the summary with links:
- [net,v2] tls: fix RX desync on overlapping skbs
https://git.kernel.org/netdev/net/c/9466ef3ec972
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html