]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tls: always refresh the queue when reading sock
authorJakub Kicinski <kuba@kernel.org>
Wed, 16 Jul 2025 14:38:50 +0000 (07:38 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 24 Jul 2025 06:53:19 +0000 (08:53 +0200)
[ Upstream commit 4ab26bce3969f8fd925fe6f6f551e4d1a508c68b ]

After recent changes in net-next TCP compacts skbs much more
aggressively. This unearthed a bug in TLS where we may try
to operate on an old skb when checking if all skbs in the
queue have matching decrypt state and geometry.

    BUG: KASAN: slab-use-after-free in tls_strp_check_rcv+0x898/0x9a0 [tls]
    (net/tls/tls_strp.c:436 net/tls/tls_strp.c:530 net/tls/tls_strp.c:544)
    Read of size 4 at addr ffff888013085750 by task tls/13529

    CPU: 2 UID: 0 PID: 13529 Comm: tls Not tainted 6.16.0-rc5-virtme
    Call Trace:
     kasan_report+0xca/0x100
     tls_strp_check_rcv+0x898/0x9a0 [tls]
     tls_rx_rec_wait+0x2c9/0x8d0 [tls]
     tls_sw_recvmsg+0x40f/0x1aa0 [tls]
     inet_recvmsg+0x1c3/0x1f0

Always reload the queue, fast path is to have the record in the queue
when we wake, anyway (IOW the path going down "if !strp->stm.full_len").

Fixes: 0d87bbd39d7f ("tls: strp: make sure the TCP skbs do not have overlapping data")
Link: https://patch.msgid.link/20250716143850.1520292-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/tls/tls_strp.c

index 1852fac3e72b7614ef56cb02b5f9cb3b6203a78e..bea60b0160d1fc34f3c57c475b2a8716d4670bd9 100644 (file)
@@ -511,9 +511,8 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
        if (inq < strp->stm.full_len)
                return tls_strp_read_copy(strp, true);
 
+       tls_strp_load_anchor_with_queue(strp, inq);
        if (!strp->stm.full_len) {
-               tls_strp_load_anchor_with_queue(strp, inq);
-
                sz = tls_rx_msg_size(strp, strp->anchor);
                if (sz < 0) {
                        tls_strp_abort_strp(strp, sz);