Skip to content

Commit d02d96b

Browse files
author
Sabrina Dubroca
committed
tls: make sure to abort the stream if headers are bogus
JIRA: https://issues.redhat.com/browse/RHEL-115640 commit 0aeb54a Author: Jakub Kicinski <kuba@kernel.org> Date: Tue Sep 16 17:28:13 2025 -0700 tls: make sure to abort the stream if headers are bogus Normally we wait for the socket to buffer up the whole record before we service it. If the socket has a tiny buffer, however, we read out the data sooner, to prevent connection stalls. Make sure that we abort the connection when we find out late that the record is actually invalid. Retrying the parsing is fine in itself but since we copy some more data each time before we parse we can overflow the allocated skb space. Constructing a scenario in which we're under pressure without enough data in the socket to parse the length upfront is quite hard. syzbot figured out a way to do this by serving us the header in small OOB sends, and then filling in the recvbuf with a large normal send. Make sure that tls_rx_msg_size() aborts strp, if we reach an invalid record there's really no way to recover. Reported-by: Lee Jones <lee@kernel.org> Fixes: 84c61fe ("tls: rx: do not use the standard strparser") Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250917002814.1743558-1-kuba@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
1 parent a0fd024 commit d02d96b

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

net/tls/tls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void update_sk_prot(struct sock *sk, struct tls_context *ctx);
139139

140140
int wait_on_pending_writer(struct sock *sk, long *timeo);
141141
void tls_err_abort(struct sock *sk, int err);
142+
void tls_strp_abort_strp(struct tls_strparser *strp, int err);
142143

143144
int init_prot_info(struct tls_prot_info *prot,
144145
const struct tls_crypto_info *crypto_info,

net/tls/tls_strp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
static struct workqueue_struct *tls_strp_wq;
1414

15-
static void tls_strp_abort_strp(struct tls_strparser *strp, int err)
15+
void tls_strp_abort_strp(struct tls_strparser *strp, int err)
1616
{
1717
if (strp->stopped)
1818
return;
@@ -210,11 +210,17 @@ static int tls_strp_copyin_frag(struct tls_strparser *strp, struct sk_buff *skb,
210210
struct sk_buff *in_skb, unsigned int offset,
211211
size_t in_len)
212212
{
213+
unsigned int nfrag = skb->len / PAGE_SIZE;
213214
size_t len, chunk;
214215
skb_frag_t *frag;
215216
int sz;
216217

217-
frag = &skb_shinfo(skb)->frags[skb->len / PAGE_SIZE];
218+
if (unlikely(nfrag >= skb_shinfo(skb)->nr_frags)) {
219+
DEBUG_NET_WARN_ON_ONCE(1);
220+
return -EMSGSIZE;
221+
}
222+
223+
frag = &skb_shinfo(skb)->frags[nfrag];
218224

219225
len = in_len;
220226
/* First make sure we got the header */
@@ -519,10 +525,8 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
519525
tls_strp_load_anchor_with_queue(strp, inq);
520526
if (!strp->stm.full_len) {
521527
sz = tls_rx_msg_size(strp, strp->anchor);
522-
if (sz < 0) {
523-
tls_strp_abort_strp(strp, sz);
528+
if (sz < 0)
524529
return sz;
525-
}
526530

527531
strp->stm.full_len = sz;
528532

net/tls/tls_sw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,8 +2460,7 @@ int tls_rx_msg_size(struct tls_strparser *strp, struct sk_buff *skb)
24602460
return data_len + TLS_HEADER_SIZE;
24612461

24622462
read_failure:
2463-
tls_err_abort(strp->sk, ret);
2464-
2463+
tls_strp_abort_strp(strp, ret);
24652464
return ret;
24662465
}
24672466

0 commit comments

Comments
 (0)