]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tls: make sure to abort the stream if headers are bogus
authorJakub Kicinski <kuba@kernel.org>
Wed, 17 Sep 2025 00:28:13 +0000 (17:28 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Sep 2025 08:58:51 +0000 (10:58 +0200)
[ Upstream commit 0aeb54ac4cd5cf8f60131b4d9ec0b6dc9c27b20d ]

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: 84c61fe1a75b ("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>
net/tls/tls.h
net/tls/tls_strp.c
net/tls/tls_sw.c

index 4922668fefaa87b60ba8dfc35265230d52df4298..f25699517bdf8f2303838451dc34b2cac55ef403 100644 (file)
@@ -91,6 +91,7 @@ int tls_sk_query(struct sock *sk, int optname, char __user *optval,
 int tls_sk_attach(struct sock *sk, int optname, char __user *optval,
                  unsigned int optlen);
 void tls_err_abort(struct sock *sk, int err);
+void tls_strp_abort_strp(struct tls_strparser *strp, int err);
 
 int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx);
 void tls_update_rx_zc_capable(struct tls_context *tls_ctx);
index b7ed76c0e576e9c61339cd5bfee9959d92ab7871..532230bed13b00b5db9fd1b9d1f5075f1aa9db57 100644 (file)
@@ -12,7 +12,7 @@
 
 static struct workqueue_struct *tls_strp_wq;
 
-static void tls_strp_abort_strp(struct tls_strparser *strp, int err)
+void tls_strp_abort_strp(struct tls_strparser *strp, int err)
 {
        if (strp->stopped)
                return;
@@ -210,11 +210,17 @@ static int tls_strp_copyin_frag(struct tls_strparser *strp, struct sk_buff *skb,
                                struct sk_buff *in_skb, unsigned int offset,
                                size_t in_len)
 {
+       unsigned int nfrag = skb->len / PAGE_SIZE;
        size_t len, chunk;
        skb_frag_t *frag;
        int sz;
 
-       frag = &skb_shinfo(skb)->frags[skb->len / PAGE_SIZE];
+       if (unlikely(nfrag >= skb_shinfo(skb)->nr_frags)) {
+               DEBUG_NET_WARN_ON_ONCE(1);
+               return -EMSGSIZE;
+       }
+
+       frag = &skb_shinfo(skb)->frags[nfrag];
 
        len = in_len;
        /* First make sure we got the header */
@@ -515,10 +521,8 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
        tls_strp_load_anchor_with_queue(strp, inq);
        if (!strp->stm.full_len) {
                sz = tls_rx_msg_size(strp, strp->anchor);
-               if (sz < 0) {
-                       tls_strp_abort_strp(strp, sz);
+               if (sz < 0)
                        return sz;
-               }
 
                strp->stm.full_len = sz;
 
index 96e62e8f1dad233606dbb2095d123a7d50458433..fe6514e964ba3a525455bfd2e2c54e8cd9035d05 100644 (file)
@@ -2435,8 +2435,7 @@ int tls_rx_msg_size(struct tls_strparser *strp, struct sk_buff *skb)
        return data_len + TLS_HEADER_SIZE;
 
 read_failure:
-       tls_err_abort(strp->sk, ret);
-
+       tls_strp_abort_strp(strp, ret);
        return ret;
 }