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 189AA80031 for ; Thu, 26 Nov 2026 06:28:54 +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 6AQ6Reso007892; Thu, 26 Nov 2026 09:27:41 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ6Reso007892 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="UWtHv59c" Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AQ6Rd52007887 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 26 Nov 2026 09:27:39 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AQ6Rd52007887 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-c42888c50c4so641729966b.0 for ; Wed, 25 Nov 2026 22:27:39 -0800 (PST) X-Gm-Message-State: APuU4Z8JqydnjRPF263KxrFnpQbr6OiT2QQWGboKHFhUVg/Kv9vBy+7s q689FW3xMTxLlwk67IQ2pbV8iMUhVdP8MHCZWWDUL+txXxqhSnNLiLtGh30+1AC8tSimMOb8u53 ZEGbh5pGXVZ4D8epP4grAnwSSX1cAns9cyCYTkgwkfOsL0QV+rHMNJQ== X-Gm-Gg: AZFdTZeEMYL4ogWrvKKmnDjnkjpc0lgrXdeVbqKZZ9IW4alaFfzNLOtmr+jOrObXZVA nof0I9ROKKpDp9I9jNncHwAuuOCeEZbEsI7DFrjNktIxKRzeD+998m6H9q2iJBtRXpOnXkZdBn6 cD1M+k9eeUtOVPr5S1ETZlWiOn7RLP4PGR/hMkpoOjj0s8sg2OqDoqq9nA/XhXFtCJKbygr03ZR 8hyavwDy41JVIs3OCl6LTJvIJc7KRxITlilyeiFfhAeUfT4rTOX7zBQWImOW6pRSgu1XVVoyLvV 36crKuhu7Yu9aSX86IBLiQYHwNgtZrF8ApRJnv5YdaVq7xnbUyE+MZXLeEobfyVxusJsuRRWNUm fCfDramcDwmPY47ZX9o1cZn8EEw== X-Received: by 2002:a17:907:608c:b0:c2e:6a4f:a88b with SMTP id a640c23a62f3a-c513a1f5c8cmr1680936666b.0.1795674458702; Wed, 25 Nov 2026 22:27:38 -0800 (PST) X-Received: by 2002:a17:907:608c:b0:c2e:6a4f:a88b with SMTP id a640c23a62f3a-c513a1f5c8cmr1680935866b.0.1795674458249; Wed, 25 Nov 2026 22:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795674458; cv=none; d=google.com; s=arc-20260327; b=VCD1xpnoAst6WemeDM1lWwNDowreBcB/pkn10IGe5ta+PEXrW5EC1XzNHK5P0tvAP1 UPO/VDbZSLJ/SdHrobA/gHdfz7nS6VWnmnz7JS9ES94K/gM2W7ZdwvXtVwqlwubn53UL wKnsvUrhagtGRjLkGYiH+v46BATouCvsmfdBgG3plpMPcoBqrGkmjzookORSOUAVjbeE RQXycettzZTzDbV4lEcG+YioljVwzgBJkM/EUF81eaIm3+8KaahbBWjqXsjHUs48KJwy 37eXxaIruTnWfpQ21fwqEsrsBR5mWjdobVnn7Ei6cODcFTC4QG6zF3i0/SZtws1Nsfcc AW8Q== 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=Z5VqP7q9XwAng/dI/zxR8wqIRTY+GL5P8MOTTBRRHgY=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=prtYtIfylAX2/+8o9ggRhXf3KDxZ2XlZv1odQjdtt/t56xVVIvLj+9fTTkwb55HgPh FhQISqIRkAZsxR50Vopne1Vq26+Ra8Lf3GtI97FxoAcJgM5lY3AXOlVlqf0L5TUYJm5b Q5q61+aku/Lv+2biksQZfMM7rYbS6ur++6rqlx/lHw2/gaejOkk+UEzmbb1FE7H1/drD itcF3mZugueRitIi2pnl7LjquJnJfsW7UNthYqXjNw3uJyMrOldzTzBaofZUgY59mGly VaK+2AEPx76Rlevby9GX0Rh7fGof8UcDYtVp5JsVe607NkgNWwSENN1f06NkATDULU4h GJ7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=UWtHv59c; 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-c513b0a75f9si1263523966b.321.2026.11.25.22.27.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 22:27: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=UWtHv59c; 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=Z5VqP7q9XwAng/dI/zxR8wqIRTY+GL5P8MOTTBRRHgY=; b=UWtHv59cl/cs zZ+DE/I2p8qsYuCpIcKv1VrNWXUVnU1FXBiyorZtXhVNUCtdXNroMge4S0K5u7l0pBCBQwHGf4wJh EnMSoThaTLSI/du3a4MVKCpd9Ve4EnqAQz+yIKxe8OpSCsZpStM8ffTFUnhMkXUkR09sk5lPntOJ6 TCAvFi6cNqo1WMmFjFS6uDG6Yyz5IZ/9kfRahBdEuMFXc1bJtIWAMxDAMKhOwsuAw2551IeEg9Ylr TxxZbp5lXFIrmHsi31RYdX7mGHBxw/icdiBx7en8GHQAoQJguZSPr2wVpqsFNbkvV9ZgD6o7bph7I l4tgJSe65bMLgpJT2Zxzkw==; 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 1xWSwO-00EFGZ-14; Thu, 26 Nov 2026 07:26:55 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 26 Nov 2026 08:11:10 +0200 Message-ID: <20261126062617.2133758-12-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126062617.2133758-2-eva.kurchatova@virtuozzo.com> References: <20261126062617.2133758-2-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v3 10/10] 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 bf1abf88cae6..8af596b3e9e0 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