tls: fix data disappearing from under the TLS ULP (CVE-2025-38616)
cover tls: fix data disappearing from under the TLS ULP (CVE-2025-38616)
Please queue these two commits for 6.1.y.
Patch 2/2 is the fix for CVE-2025-38616. It is already present in every other supported stable tree: 6.6.y since 6.6.103, 6.12.y since 6.12.43, and 6.18.y and 7.1.y inherit it from v6.17. 6.1.y is the only supported affected tree still missing it. The upstream commit carries no Cc: stable trailer, which is why 6.1.y was left behind.
Patch 1/2 is a prerequisite. In 6.1.y strp->msg_ready is still a bitfield, so the WRITE_ONCE() added by 2/2 does not compile there:
./include/asm-generic/rwonce.h:55:32: error: cannot take address of bit-field 'msg_ready'
Backporting 0844370f8945 first converts the field to a bool, which lets 2/2 apply and build unmodified. 0844370f8945 also fixes a real bug that 6.1.y still has on its own: a lockless read of msg_ready in ->poll. It is present in 6.6.y and later, so no newer stable tree regresses.
Both patches are verbatim upstream cherry-picks with no adaptation. Verified on v6.1.183: both apply with no conflict, and net/tls builds clean, including with CONFIG_DEBUG_NET=y.
CVE-2025-38616 was reproduced on a KASAN v6.1.182 build; the patched kernel survived 1,000 rounds of the reproducer.
Jakub Kicinski (1):
tls: handle data disappearing from under the TLS ULP
Sabrina Dubroca (1):
tls: fix lockless read of strp->msg_ready in ->poll
include/net/tls.h | 3 ++- net/tls/tls.h | 4 ++-- net/tls/tls_strp.c | 17 +++++++++++------ net/tls/tls_sw.c | 3 ++- 4 files changed, 17 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 tls: fix lockless read of strp->msg_ready in ->poll
From: Sabrina Dubroca <[email protected]>
[ Upstream commit 0844370f8945086eb9335739d10205dcea8d707b ]
tls_sk_poll is called without locking the socket, and needs to read strp->msg_ready (via tls_strp_msg_ready). Convert msg_ready to a bool and use READ_ONCE/WRITE_ONCE where needed. The remaining reads are only performed when the socket is locked.
---
Prerequisite for 2/2, applied verbatim with no source adaptation. This also fixes a real lockless read of msg_ready in ->poll that 6.1.y has on its own.
include/net/tls.h | 3 ++- net/tls/tls.h | 2 +- net/tls/tls_strp.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-)
include/net/tls.h +2 -1
@@ -122,7 +122,8 @@ struct tls_strparser { u32 stopped : 1; u32 copy_mode : 1; u32 mixed_decrypted : 1; - u32 msg_ready : 1; + +bool msg_ready;struct strp_msg stm;
net/tls/tls.h +1 -1
@@ -167,7 +167,7 @@ static inline struct sk_buff *tls_strp_msg(struct tls_sw_context_rx *ctx)static inline bool tls_strp_msg_ready (struct tls_sw_context_rx *ctx) { -return ctx->strp.msg_ready; +return READ_ONCE (ctx->strp.msg_ready); }static inline bool tls_strp_msg_mixed_decrypted (struct tls_sw_context_rx *ctx)
net/tls/tls_strp.c +3 -3
@@ -366,7 +366,7 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,if (strp->stm.full_len && strp->stm.full_len == skb->len) { desc->count =0 ; - strp->msg_ready =1 ; +WRITE_ONCE (strp->msg_ready,1 );tls_rx_msg_ready (strp); }
@@ -533,7 +533,7 @@ static int tls_strp_read_sock(struct tls_strparser *strp)if (!tls_strp_check_queue_ok (strp))return tls_strp_read_copy (strp, false); - strp->msg_ready =1 ; +WRITE_ONCE (strp->msg_ready,1 );tls_rx_msg_ready (strp);return 0 ;
@@ -585,7 +585,7 @@ void tls_strp_msg_done(struct tls_strparser *strp)else tls_strp_flush_anchor_copy (strp); - strp->msg_ready =0 ; +WRITE_ONCE (strp->msg_ready,0 );memset (&strp->stm,0 ,sizeof (strp->stm));tls_strp_check_rcv (strp);
Signature · 1 line
2.43.0
PATCH 2/2 tls: handle data disappearing from under the TLS ULP
In reply to Artem DinaburgFrom: Jakub Kicinski <[email protected]>
[ Upstream commit 6db015fc4b5d5f63a64a193f65d98da3a7fc811d ]
TLS expects that it owns the receive queue of the TCP socket. This cannot be guaranteed in case the reader of the TCP socket entered before the TLS ULP was installed, or uses some non-standard read API (eg. zerocopy ones). Replace the WARN_ON() and a buggy early exit (which leaves anchor pointing to a freed skb) with real error handling. Wipe the parsing state and tell the reader to retry.
We already reload the anchor every time we (re)acquire the socket lock, so the only condition we need to avoid is an out of bounds read (not having enough bytes in the socket for previously parsed record len).
If some data was read from under TLS but there's enough in the queue we'll reload and decrypt what is most likely not a valid TLS record. Leading to some undefined behavior from TLS perspective (corrupting a stream? missing an alert? missing an attack?) but no kernel crash should take place.
---
The CVE-2025-38616 fix, applied verbatim with no source adaptation. Patch 1/2 supplies the bool msg_ready that this patch's WRITE_ONCE() requires.
net/tls/tls.h | 2 +- net/tls/tls_strp.c | 11 ++++++++--- net/tls/tls_sw.c | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-)
net/tls/tls.h +1 -1
@@ -147,7 +147,7 @@ void tls_strp_msg_done(struct tls_strparser *strp);int tls_rx_msg_size (struct tls_strparser *strp,struct sk_buff *skb);void tls_rx_msg_ready (struct tls_strparser *strp); -void tls_strp_msg_load (struct tls_strparser *strp,bool force_refresh); +bool tls_strp_msg_load (struct tls_strparser *strp,bool force_refresh);int tls_strp_msg_cow (struct tls_sw_context_rx *ctx);struct sk_buff *tls_strp_msg_detach (struct tls_sw_context_rx *ctx);int tls_strp_msg_hold (struct tls_strparser *strp,struct sk_buff_head *dst);
net/tls/tls_strp.c +8 -3
@@ -481,7 +481,7 @@ static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, int len) strp->stm.offset = offset; } -void tls_strp_msg_load (struct tls_strparser *strp,bool force_refresh) +bool tls_strp_msg_load (struct tls_strparser *strp,bool force_refresh) {struct strp_msg *rxm;struct tls_msg *tlm;
@@ -490,8 +490,11 @@ void tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)DEBUG_NET_WARN_ON_ONCE (!strp->stm.full_len);if (!strp->copy_mode && force_refresh) { -if (WARN_ON (tcp_inq (strp->sk) < strp->stm.full_len)) -return ; +if (unlikely (tcp_inq (strp->sk) < strp->stm.full_len)) { +WRITE_ONCE (strp->msg_ready,0 ); +memset (&strp->stm,0 ,sizeof (strp->stm)); +return false; + }tls_strp_load_anchor_with_queue (strp, strp->stm.full_len); }
@@ -501,6 +504,8 @@ void tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh) rxm->offset = strp->stm.offset; tlm =tls_msg (strp->anchor); tlm->control = strp->mark; + +return true; }/* Called with lock held on lower socket */
net/tls/tls_sw.c +2 -1
@@ -1510,7 +1510,8 @@ tls_rx_rec_wait(struct sock *sk, struct sk_psock *psock, bool nonblock,return sock_intr_errno (timeo); } -tls_strp_msg_load (&ctx->strp, released); +if (unlikely (!tls_strp_msg_load (&ctx->strp, released))) +return tls_rx_rec_wait (sk, psock, nonblock, false);return 1 ; }
Signature · 1 line
2.43.0