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 7672480031 for ; Tue, 1 Dec 2026 15:39:32 +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 6B1FcKeB020101; Tue, 1 Dec 2026 18:38:20 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1FcKeB020101 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="EiVXs3MJ" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1FbsSI019982 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 18:37:55 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1FbsSI019982 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6ba62acd927so10715402a12.3 for ; Tue, 01 Dec 2026 07:37:55 -0800 (PST) X-Gm-Message-State: APuU4Z9TXQp/6QFR6DpYfhNcxCF+YGJpzpEfUqanff3vBsZJnqSFBR+U yduMS/sZlheGQHNXzMDmn7r+SLAsH4gU/IkB/usWnwo8E7I/f9muNZ/BuvcWGr8QnhUOw8OQN8u fiUNjJX5ceS8QpI9Ad/w6DEloHZtu9f87UziVQTtZrU0Xt94VvDP7hg== X-Gm-Gg: AZFdTZcu0pq96+hAPW2OgPJgZJLgMMCAfYVmPJnTqkiHDJTwzy12BwCvpObUdnOEloo 0sk/qwoF0/6z2RgxGGCCXHfxlmP59Sxy8up5bD+ikcEbGSvlQmEjQfYw+r+KpkQhBzs0/pWCDAw jVc7Vt97qIZvvuAn7OgCaZaxuhCjmutR24QU3ScBZ+hAUPvoyMC+tIb36u7hqXPQlrRAsVGnaDN 20toHrT1at+ZC588hrifUl3ylOr7zhfyj942thWNMwbI0/WzLDiDJXFJEEQgIC7/VPvo9ba3+Tt c0zTPRQNgJTaCx7GuHJ74+wJLuR2arNzZeRTl7YJQfLB//g5+UcrN9ShS8YtiaRCsm++YdOlDoo MOjnq2W74FH/gRi2Wsk/RlCzilQ== X-Received: by 2002:a05:6402:1ec9:b0:6ba:38c1:57e7 with SMTP id 4fb4d7f45d1cf-6ba38c16228mr26089976a12.24.1796139474468; Tue, 01 Dec 2026 07:37:54 -0800 (PST) X-Received: by 2002:a05:6402:1ec9:b0:6ba:38c1:57e7 with SMTP id 4fb4d7f45d1cf-6ba38c16228mr26089962a12.24.1796139473875; Tue, 01 Dec 2026 07:37:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796139473; cv=none; d=google.com; s=arc-20260327; b=G1WjXf/uU8A5a4bBzqjmFND5rhCa83stkIucN//xi6oizpP84BNaI5+oskjwjUBUNq 8O31t/hf/W8wwmMbSUWt7OrCR4Nb1sCre12KeC41W4w/cUWGCDCv7Z8xBuEQbsVMXRo5 M/MjBbG9M7flVBaB1HsKzVYypAbK3bS08dgP0mpiiBosdEJ5KtXV4BRsnEEXyEyIRAI4 p6hoZCeDScA0ue47JwHcqKEZzwEpp1Y8MrBOa3HQgrur69DowCsZYPwdlIVXq5pZ04QG ch/lQKmxz7AF8gVYeYpSXw1cSczCEcQ33IQ1TTazvzCmivDuCrEYyp1UyzrgUM/M9hVK 4rWw== 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=3F86M9B8yAW5Gz+1FeU8eEL8PIpxr0tKm0m/jHgysdY=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=n1i4qYHfoChb5eF1WMF44NCihT1RJfgiPlNTtvH/zgOyw1PCn4mmnSgox6sAUbHD2A K7qxA6xFzB4ZoMa3/+2H69BZitrPteCmayRQGBIkx9KmsBjOT2AFvqpmhZH6oejIZ1dL 0vOWYWS0vq2OxRuwdqib090PhUa/nhRQ/FG0sw5c3/LNDQcc1ZyRsdn2aqkYWqOfInJN UaecVZoEVSgo0p9ukt/f+riJ2gYLmaSHrJ0Ed8v1JFDYxOBsRpAFMrHWA1NTgkwrr0R7 bFx18uOVjO+dhcUx8Ecv2iCV9gfIxoLpOBCnhKqxuyDR0vcsAPiYiWJJtpcpUwttXyda ws6A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=EiVXs3MJ; 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 4fb4d7f45d1cf-6baea78f06bsi19350924a12.24.2026.12.01.07.37.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:37:53 -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=EiVXs3MJ; 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=3F86M9B8yAW5Gz+1FeU8eEL8PIpxr0tKm0m/jHgysdY=; b=EiVXs3MJiEVa +u6gorFgl7NDQ1KxFSWcA9YjZWpINSCiNAPEGQiyYRIslB+aJzMyvB+3Ib6KRPlha+X9Cux4U+xxD q479nM0R+TSsPxoK/GKy7LZrlt1+pwJ+dBS/dCB4qGZxuRN5NzJkljW1RYlW94hdTINdEjmlZdwjF gkhReYqW1oSOV4ozHQP++leQOsDOFM0+mSAlqXTDZClc55lyIluCk4vCsMw969ha/zXiHZ58gMjYs 6D2V8OGKLt4oTELzWrF52bISQAZD2ZICdKuHmewnKYacfGhy3O03JU273Et2VJLWyAbFwPNTlr9oR YGQEs549K1DXCEga2d7nMg==; 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 1xYPvA-0081OE-2w; Tue, 01 Dec 2026 16:37:43 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Tue, 1 Dec 2026 14:10:22 +0200 Message-ID: <20261201153749.2872789-8-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com> References: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 07/15] ms/tcp: fix NULL pointer dereference when restarting a Fast Open listener 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 When a valid RST is received for a Fast Open child accepted before the three-way handshake completes, reqsk_fastopen_remove() adds the request_sock to the listener's RST list if the listener is in TCP_LISTEN. An application can call shutdown(SHUT_RD) on a listener socket. inet_csk_listen_stop() checks rskq_rst_head without holding fastopenq.lock. If rskq_rst_head is NULL, it does not acquire the lock and therefore does not synchronize with an insertion by reqsk_fastopen_remove() after that function has passed the TCP_LISTEN check. The more likely outcome of this race, even without a subsequent listen(), is a leak. If reqsk_fastopen_remove() inserts a request_sock after inet_csk_listen_stop() observes an empty list and returns, the request_sock is stranded in rskq_rst_head and keeps a reference on the listener. The socket is already in TCP_CLOSE, so a subsequent close() does not call inet_csk_listen_stop() again. If listen() is called again on the same socket before the delayed list insertion, the insertion can overlap the queue initialization in reqsk_queue_alloc(). If it occurs after rskq_rst_head is set to NULL but before rskq_rst_tail is set to NULL, rskq_rst_head points to the request_sock while rskq_rst_tail is NULL. When a valid RST is later received for another accepted Fast Open child, rskq_rst_head is not NULL, so reqsk_fastopen_remove() attempts to write the request_sock pointer to rskq_rst_tail->dl_next while rskq_rst_tail is NULL. KASAN reports: BUG: KASAN: null-ptr-deref in reqsk_fastopen_remove+0x147/0x210 Write of size 8 at addr 0000000000000088 by task swapper/3/0 ... Call Trace: ... reqsk_fastopen_remove+0x147/0x210 tcp_check_req+0xa70/0x1060 ... tcp_rcv_state_process+0x1cb/0x2ae0 ... tcp_v4_do_rcv+0x1fe/0x740 tcp_v4_rcv+0x1744/0x2070 ... ip_protocol_deliver_rcu+0x5c/0x280 ip_local_deliver_finish+0x171/0x330 ip_local_deliver+0x107/0x370 ... To widen the race window, the issue was reproduced after adding mdelay(3000) immediately after reqsk_fastopen_remove() checks that the listener is in TCP_LISTEN and immediately after reqsk_queue_alloc() sets rskq_rst_head to NULL. Make inet_csk_listen_stop() acquire fastopenq.lock regardless of the value of rskq_rst_head and detach the list while holding the lock. With this synchronization, reqsk_fastopen_remove() either inserts the request_sock before inet_csk_listen_stop() acquires the lock, in which case inet_csk_listen_stop() reclaims it, or sees that the listener is not in TCP_LISTEN and does not insert anything. Fixes: 0536fcc039a8 ("tcp: prepare fastopen code for upcoming listener changes") Cc: stable@vger.kernel.org Signed-off-by: Hyunwoo Kim Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/avMkfJrXhCFXn8M_@v4bel Signed-off-by: Jakub Kicinski (cherry picked from commit aa40afa831ebfe45e40a23721711059f2ac584d4) https://virtuozzo.atlassian.net/browse/VSTOR-157577 Feature: fix ms/net Signed-off-by: Eva Kurchatova Reviewed-by: Sashiko --- net/ipv4/inet_connection_sock.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index e8c2070ad7f0..bc4c732946bb 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1523,17 +1523,15 @@ void inet_csk_listen_stop(struct sock *sk) if (!has_current_bpf_ctx()) cond_resched(); } - if (queue->fastopenq.rskq_rst_head) { - /* Free all the reqs queued in rskq_rst_head. */ - spin_lock_bh(&queue->fastopenq.lock); - req = queue->fastopenq.rskq_rst_head; - queue->fastopenq.rskq_rst_head = NULL; - spin_unlock_bh(&queue->fastopenq.lock); - while (req != NULL) { - next = req->dl_next; - reqsk_put(req); - req = next; - } + /* Free all the reqs queued in rskq_rst_head. */ + spin_lock_bh(&queue->fastopenq.lock); + req = queue->fastopenq.rskq_rst_head; + queue->fastopenq.rskq_rst_head = NULL; + spin_unlock_bh(&queue->fastopenq.lock); + while (req != NULL) { + next = req->dl_next; + reqsk_put(req); + req = next; } WARN_ON_ONCE(sk->sk_ack_backlog); } -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel