tls: fix RX desync on overlapping skbs
Subsystems (3)
PATCH 1/1 tls: fix RX desync on overlapping skbs
On a reordering path (e.g. IPsec crypto offload + GRO) 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 skb ranges don't overlap.
When a record boundary lands within the last few bytes of an skb, the 5-byte header straddles into the overlapping next skb; the duplicate bytes are read as the header, yielding a bogus length (-EMSGSIZE) or version (-EINVAL) and aborting the connection.
tls_strp_check_queue_ok() already detects such overlaps and diverts to the seq-addressed copy path, but it only ran after the header was parsed, and it validated stm.offset + stm.full_len -- and full_len is still 0 for a new record, so it could not cover the header bytes. Parameterize it by length and also validate the header region (stm.offset + TLS_HEADER_SIZE) before parsing.
---
Tested on Linux kernel 7.2 rc6
--- net/tls/tls_strp.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
net/tls/tls_strp.c +9 -3
@@ -430,9 +430,9 @@ 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;struct sk_buff *first, *skb;u32 seq;
@@ -525,6 +525,12 @@ 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, strp->stm.offset +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.offset + strp->stm.full_len))return tls_strp_read_copy (strp, false);WRITE_ONCE (strp->msg_ready,1 );
Signature · 1 line
2.55.0
Jakub Kicinski
maintainerQuoted 1 line · On Fri, 7 Aug 2026 19:31:05 +0200 Maximilian Immanuel Brandtner wrote:
On a reordering path (e.g. IPsec crypto offload + GRO) the TCP receive
It'd be better to move this "IPsec crypto offload + GRO" to the end, it's not super relevant to the problem. Mention that you observe this in real life and that "IPsec crypto offload + GRO" is the likely culprit. Mentioning the NIC may also be useful to other users.
Quoted 10 lines
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 skb ranges don't overlap.
When a record boundary lands within the last few bytes of an skb, the 5-byte header straddles into the overlapping next skb; the duplicate bytes are read as the header, yielding a bogus length (-EMSGSIZE) or version (-EINVAL) and aborting the connection.
tls_strp_check_queue_ok()already detects such overlaps and diverts to the seq-addressed copy path, but it only ran after the header was parsed,
The rest of this paragraph below looks like slop, don't describe what the patch does. We can hopefully see that from the diff.
Quoted 19 lines
and
it validated stm.offset + stm.full_len -- andfull_lenis still 0 for a new record, so it could not cover the header bytes. Parameterize it by length and also validate the header region (stm.offset +TLS_HEADER_SIZE) before parsing.Fixes 84c61fe1a75b ("tls: rx: do not use the standard strparser")Signed-off-by Maximilian Immanuel Brandtner <[email protected]>---
Tested on Linux kernel 7.2 rc6--- net/tls/tls_strp.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)net/tls/tls_strp.c +0
-0
net/tls/tls_strp.c static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort) · line 435
Quoted 8 lines
net/tls/tls_strp.c +2
-2@@ -430,9 +430,9 @@ 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;
keep the stm.offset addition here, it's doesn't belong in the caller
net/tls/tls_strp.c static int tls_strp_read_sock(struct tls_strparser *strp) · line 530
Quoted 10 lines
net/tls/tls_strp.c +3
-0struct sk_buff *first, *skb;u32 seq;@@ -525,6 +525,12 @@ 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); +
no empty line between the two checks
Quoted 2 lines
net/tls/tls_strp.c +2
-0+if (!tls_strp_check_queue_ok (strp, strp->stm.offset +TLS_HEADER_SIZE )) +return tls_strp_read_copy (strp, false);