Skip to content

Commit b364621

Browse files
kuba-moogregkh
authored andcommitted
tls: make sure to abort the stream if headers are bogus
[ Upstream commit 0aeb54a ] 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: Sasha Levin <sashal@kernel.org>
1 parent 17d6997 commit b364621

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
@@ -91,6 +91,7 @@ int tls_sk_query(struct sock *sk, int optname, char __user *optval,
9191
int tls_sk_attach(struct sock *sk, int optname, char __user *optval,
9292
unsigned int optlen);
9393
void tls_err_abort(struct sock *sk, int err);
94+
void tls_strp_abort_strp(struct tls_strparser *strp, int err);
9495

9596
int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx);
9697
void tls_update_rx_zc_capable(struct tls_context *tls_ctx);

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 */
@@ -515,10 +521,8 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
515521
tls_strp_load_anchor_with_queue(strp, inq);
516522
if (!strp->stm.full_len) {
517523
sz = tls_rx_msg_size(strp, strp->anchor);
518-
if (sz < 0) {
519-
tls_strp_abort_strp(strp, sz);
524+
if (sz < 0)
520525
return sz;
521-
}
522526

523527
strp->stm.full_len = sz;
524528

net/tls/tls_sw.c

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

24372437
read_failure:
2438-
tls_err_abort(strp->sk, ret);
2439-
2438+
tls_strp_abort_strp(strp, ret);
24402439
return ret;
24412440
}
24422441

0 commit comments

Comments
 (0)