Skip to content

Commit bb0e0fd

Browse files
author
Sabrina Dubroca
committed
tls: handle data disappearing from under the TLS ULP
JIRA: https://issues.redhat.com/browse/RHEL-115640 commit 6db015f Author: Jakub Kicinski <kuba@kernel.org> Date: Thu Aug 7 16:29:06 2025 -0700 tls: handle data disappearing from under the TLS ULP 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. Reported-by: William Liu <will@willsroot.io> Reported-by: Savino Dicanosa <savy@syst3mfailure.io> Link: https://lore.kernel.org/tFjq_kf7sWIG3A7CrCg_egb8CVsT_gsmHAK0_wxDPJXfIzxFAMxqmLwp3MlU5EHiet0AwwJldaaFdgyHpeIUCS-3m3llsmRzp9xIOBR4lAI=@syst3mfailure.io Fixes: 84c61fe ("tls: rx: do not use the standard strparser") Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20250807232907.600366-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
1 parent 330442d commit bb0e0fd

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

net/tls/tls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void tls_strp_msg_done(struct tls_strparser *strp);
197197
int tls_rx_msg_size(struct tls_strparser *strp, struct sk_buff *skb);
198198
void tls_rx_msg_ready(struct tls_strparser *strp);
199199

200-
void tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh);
200+
bool tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh);
201201
int tls_strp_msg_cow(struct tls_sw_context_rx *ctx);
202202
struct sk_buff *tls_strp_msg_detach(struct tls_sw_context_rx *ctx);
203203
int tls_strp_msg_hold(struct tls_strparser *strp, struct sk_buff_head *dst);

net/tls/tls_strp.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, int len)
474474
strp->stm.offset = offset;
475475
}
476476

477-
void tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
477+
bool tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
478478
{
479479
struct strp_msg *rxm;
480480
struct tls_msg *tlm;
@@ -483,8 +483,11 @@ void tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
483483
DEBUG_NET_WARN_ON_ONCE(!strp->stm.full_len);
484484

485485
if (!strp->copy_mode && force_refresh) {
486-
if (WARN_ON(tcp_inq(strp->sk) < strp->stm.full_len))
487-
return;
486+
if (unlikely(tcp_inq(strp->sk) < strp->stm.full_len)) {
487+
WRITE_ONCE(strp->msg_ready, 0);
488+
memset(&strp->stm, 0, sizeof(strp->stm));
489+
return false;
490+
}
488491

489492
tls_strp_load_anchor_with_queue(strp, strp->stm.full_len);
490493
}
@@ -494,6 +497,8 @@ void tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
494497
rxm->offset = strp->stm.offset;
495498
tlm = tls_msg(strp->anchor);
496499
tlm->control = strp->mark;
500+
501+
return true;
497502
}
498503

499504
/* Called with lock held on lower socket */

net/tls/tls_sw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,8 @@ tls_rx_rec_wait(struct sock *sk, struct sk_psock *psock, bool nonblock,
13991399
return sock_intr_errno(timeo);
14001400
}
14011401

1402-
tls_strp_msg_load(&ctx->strp, released);
1402+
if (unlikely(!tls_strp_msg_load(&ctx->strp, released)))
1403+
return tls_rx_rec_wait(sk, psock, nonblock, false);
14031404

14041405
return 1;
14051406
}

0 commit comments

Comments
 (0)