From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id A43EF80031 for ; Wed, 25 Nov 2026 06:23:25 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP6MAXa016565; Wed, 25 Nov 2026 09:22:10 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6MAXa016565 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="k5o+eMiL" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP6LdpZ016498 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 09:21:39 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6LdpZ016498 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c5101fd59e3so466655566b.0 for ; Tue, 24 Nov 2026 22:21:39 -0800 (PST) X-Gm-Message-State: APuU4Z/XzKDAI/kWNQophnlCicfm0Tw3twRg0NlHI4lG8coZYZ+opC6R UnN//J/3NpMO9+Qnfe0+ZmLojwlRSTtnZryF4wjaeBTzmlqbu9eyN2D8xHHLEmyGpxyHJUqTSjK qRGU+3HlZpOmi1waXETbvF3DVImwUfW4KjLotKQQDkUzU51HjoTf0iA== X-Gm-Gg: AZFdTZdnzKeOjTPilaUCUM7TWY73J8SEIsOcyArFjfcdYXC/D7hMdvwek6gQiSYN9te dbviccKkGWzO31z3qtUGnVTlx4Q+4UiBp8u2NBtkA7DqUSITevdbZZT8nBCjzlZwLSNN0F3zbzg pvKqdHsfLRXzPAmVMUh7MJj19QO1djLPdQDaJSmPy6LunQhI9i4KAQfEGWDqkpbX5TO69DUvqhw gr7g7J2h5MC4n8H7mwAq0G+mGzF13cNISG98K1Iu1cF2KYZcGo+IgZ55uwNBLczK8DjfUdKBIe3 CD4ly6UqGC+GM105B+5tTbtJtjqOBJAsGabGx0xwmn/uAv/Y5SsowlGt0qn80KH9VNsXFreVjq8 f3Q7qXLnIRhkHlDTXjGYjhPx/sw== X-Received: by 2002:a17:907:7f91:b0:c50:c04d:cbb4 with SMTP id a640c23a62f3a-c513ac9f641mr1434383866b.43.1795587698849; Tue, 24 Nov 2026 22:21:38 -0800 (PST) X-Received: by 2002:a17:907:7f91:b0:c50:c04d:cbb4 with SMTP id a640c23a62f3a-c513ac9f641mr1434382966b.43.1795587698397; Tue, 24 Nov 2026 22:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795587698; cv=none; d=google.com; s=arc-20260327; b=IgA3jm+Tjg8kASUIYu8hoWDGRNWPjc+F3YPdC6B0Qq88+Jx4mfKogDGnMBHFDciQNQ UpDFgQGKZdMNeoo66PTAgksFv23b5CyBaq54fC4UK8mkFgGBtCESsFRERenWN2QrPFlf QaWwRa5S2uU1YD2/y9zYpzTIQg+MYWz5WWD+ZJ5rNOadyvu+g5dU8fH8gQbjiOdcGmeU Y2Gep8E+av+hiByqPzYEjEtQkNmo+OD3rJoDfRG4HYdoFIgytjXdgUPb8nNOJnP/u8fA LFHiEZanR3HH5gojrerXN85rF2OIv/xYgnCnjY+HU/z67EAxq6DpauxGqcPJGws+ix+6 LOxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Z4Oxtr4mI/h6xt0FF3PDXoCEWo1QmKQleVWv6fT+7/U=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=sa13c9sdToSmaDCxn7M9uoDdXT+kQeI6j7Qu2h6Rp4wbMVoS6eN2eIXTZKZJ22zz0J U8MmHyk1VW5W4K+DL4KtZKmHWhbENbE7m+glF9GPqtJT2Wz2XKRFsImbcKYKVq8sGfHd ckWSLfudyLlIGiv2608GB1mnDiVMFk1lEKruke6Sc0/Cb0gqAQycGQbSOZC3UhOswXxp L3c6U5zbPgWB+xm+1T2ECfOfOTSHK8O0IrSbWk+B1zk65BWj3uGRQ9kNHTGcUvL5nOLY 3J5gKfToUMhUlUcewWR+GwFwAM4l/nthqyIvcQAPvG/i4lyn5sMQBFCpbZ5ElKrrrnl+ AMgA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=k5o+eMiL; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513b0aac55si1099832266b.331.2026.11.24.22.21.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 22:21:38 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=k5o+eMiL; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=Z4Oxtr4mI/h6xt0FF3PDXoCEWo1QmKQleVWv6fT+7/U=; b=k5o+eMiLN5fJ iDnb0iZr2Zymn76aHthhN5M8H+WxY+wo6OeSx2H7b4hfovdMc7TcRI9nTlbdIpa0HZ/5O+zfwzkui AKHit9cbV/eFxnhZwOsA66VFRidvhaeAXxw0meaEHaFS7dJ8q/J+ABA5YBS75wBasjVTX2Kz0TWJ/ +GqTnVpqk2/CoB3/TIvD44xCxHgseJC/JidNUsOQ/bvFlEkk9o0/GxW7FnW+MRbM4zhMApcdDDLU5 IJ/fMI7zVyXhl8tNSvo0VzlusVH/dF0yXXXwySCP91ouzjaCJMOPHgTGy8uwOX0bA9+D4fxghDl9H mr7vw/BfUlFFlHXgkQ2z6g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xW6Nj-006mb7-0X; Wed, 25 Nov 2026 07:21:37 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Wed, 25 Nov 2026 08:14:18 +0200 Message-ID: <20261125062128.1996509-9-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125062128.1996509-1-eva.kurchatova@virtuozzo.com> References: <20261125062128.1996509-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 8/8] ms/tcp: fix request_sock use-after-free during Fast Open accept() X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Hyunwoo Kim Commit e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()") made inet_csk_accept() check tfo_listener before taking fastopenq.lock to avoid taking the lock for connections that did not use Fast Open. reqsk_fastopen_remove() clears tfo_listener while holding fastopenq.lock, then reads req->sk. If inet_csk_accept() concurrently observes tfo_listener after it has been cleared, it skips fastopenq.lock and drops the last reference to the request_sock. This can free the request_sock while reqsk_fastopen_remove() is still using it. If the freed memory is reused for a new request_sock with req->sk == NULL, the reset path in reqsk_fastopen_remove() can append the new request_sock to the original listener's list of requests that caused an RST. After the new request_sock is freed, the next append writes through the stale rskq_rst_tail into freed memory. KASAN reported the following use-after-free when writing fastopenq->rskq_rst_tail->dl_next = req: BUG: KASAN: slab-use-after-free in reqsk_fastopen_remove+0x142/0x210 Write of size 8 at addr ffff888108230688 by task swapper/5/0 ... Call Trace: ... reqsk_fastopen_remove+0x142/0x210 tcp_check_req+0x96f/0xdd0 ... tcp_rcv_state_process+0x19c/0x26b0 ... tcp_v4_do_rcv+0x16e/0x490 tcp_v4_rcv+0x14a0/0x1af0 ... ip_protocol_deliver_rcu+0x39/0x1e0 ip_local_deliver_finish+0x124/0x1e0 ip_local_deliver+0xfb/0x1e0 ... To widen the race windows, mdelay(5) was added after newsk = req->sk, mdelay(20) after the if (req) reqsk_put(req) block, and mdelay(100) after tcp_rsk(req)->tfo_listener = false. The KASAN report above was reproduced with this kernel. For the lockless check, use tcp_sk(newsk)->syn_fastopen_child instead of tfo_listener, which reqsk_fastopen_remove() clears. syn_fastopen_child is a field of the Fast Open child TCP socket referenced by newsk, not of the request_sock. It is set before the child socket is added to the accept queue. The paths that call reqsk_fastopen_remove() in response to a remote ACK or RST do not clear this field. inet_csk_accept() uses this field to take fastopenq.lock only for Fast Open child sockets and rechecks tfo_listener while holding the lock. Connections that did not use Fast Open continue to avoid the lock. Fixes: e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()") Cc: stable@vger.kernel.org Signed-off-by: Hyunwoo Kim Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/avQKA_YTAThtbsYU@v4bel Signed-off-by: Jakub Kicinski (cherry picked from commit 62754aad50d0b30938bd8ce30b43474ce502a2af) https://virtuozzo.atlassian.net/browse/VSTOR-156045 Feature: fix ms/net Signed-off-by: Eva Kurchatova --- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 63af4334d65c..eff71800137f 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -681,7 +681,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg) newsk = req->sk; if (sk->sk_protocol == IPPROTO_TCP && - tcp_rsk(req)->tfo_listener) { + tcp_sk(newsk)->syn_fastopen_child) { spin_lock_bh(&queue->fastopenq.lock); if (tcp_rsk(req)->tfo_listener) { /* We are still waiting for the final ACK from 3WHS -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel