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 4978A80031 for ; Mon, 30 Nov 2026 18:50:07 +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 6AUImtSE031168; Mon, 30 Nov 2026 21:48:55 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AUImtSE031168 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="rXosxoIm" Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AUImYBU031090 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 30 Nov 2026 21:48:34 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AUImYBU031090 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-c505ee61160so1012278266b.0 for ; Mon, 30 Nov 2026 10:48:34 -0800 (PST) X-Gm-Message-State: APuU4Z/OlVt/1yu2jkIcBicjQKLqJPVxNeUhz8Yw0GRBJZh0GouVBIEg ZXSV75FnaNtPxRHMEJic/X7kUac8GWORzUVVY7F7/To1lR6GtlKZqmsgHkShkcUIzfIspS4DR6w jWWzgzQkv/Q61Rt3NGd/EvM1E41uFqs9wl57DbgbfTlPVNNyi2tX+0Q== X-Gm-Gg: AZFdTZcXLLhtCAdxoy4kNTrSLIKJrCxki2jBA5/Z3rhVosHCQaZ0lfPVKfocQxzlAjp VxhDxeIyQiC7AeYnJNnNIvmoXG17C+qRNYsSkdNVmbTT5DrmVqaJHpcRrTvmaG0FUVR+FO+DO7t Q4PEzp0ps5jy0CYSH0oMzc6BoGT3PhrmGbVsvpnyEZjdc1oSRKyZT7roz4ihPLmlVVWNgxcNkNG SoX63DhUeKLsdDzBS1A28LJZqOyBxjBJTHDDXJTCOc3IzgtuRbc7wLjsFHxdhWqyQDPNVm2QsUN Rc73EyWwWvsB4GwWrZPe7jZh8+kUoHqXwColICC6Smm2iVbcRTRdKUrfwECClFNFpc1TeaGxX1v nf9lPT/cOYkyTC2kDa470j8hr0g== X-Received: by 2002:a17:907:2d91:b0:c51:982e:28bf with SMTP id a640c23a62f3a-c51982e29d1mr1577215866b.40.1796064514212; Mon, 30 Nov 2026 10:48:34 -0800 (PST) X-Received: by 2002:a17:907:2d91:b0:c51:982e:28bf with SMTP id a640c23a62f3a-c51982e29d1mr1577214166b.40.1796064513711; Mon, 30 Nov 2026 10:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796064513; cv=none; d=google.com; s=arc-20260327; b=Y+yXqu/b3NEZoJBH1DVgw9jjoXkOQUmcK15c5PDUJhEFgCCkP2CW0kp9uiDpFCalUS SsO3PE0rWUP5Dp3U8Ist9WemTSwwzqAaQQecQvNgYeQ9CgUk6JGFUTAc7r/Ki1z1MFL9 3m8fGInOzQ0R4B+eKl6ttQ6VPVk4auG2oba5zFlAYD0JHJO3VNcR6563iBCIXC6PpgL2 EpExcYvX4pEb+u7/dZeQWbgbRuZwjph+JhDWSO8Wrhaz66w8LH00RnM3PZA0igmjeW+T vo5ru+wgDPCPJ8csaYzTPTLvf57end30CE0aDnYCoYEsR3PvX1wjFmxoSg8txXcTUSO+ Szgw== 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=xgLAUUsEzdHh4+rBuW2IGtJpzZAmT+NRg85Cmz1rGh4=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=TmbrIoyPoseD7Badi6vDvmg++jdH8TIv5yBTIn8Qx6QiSyWTIjAIadINSwST59N5X/ yraI8x8eqER5F05sbbL6HuHvwip73Gh8c3LmZd0QV0p6yP29wTTIM6+5+TjB7kdLeLMB ReGvZaX2bt8k5b9eTFmuSHZZELaSQtDluaeRHSxeXhiSSu0SuDeMqoPs9YrHUaNBHtB2 IXhgG3SRyH9Q6rGPrI1WxY3g/7zpf/IdTssDpoXDtWeMtFMyTlIRNphN445L0D73W2h+ f9SlkFGa2jKAhrOz2DX7u9Rh7eXQ4HV8tNFhMjOMfqM4V4I2iue7QBzO2KuuulyZon41 pY3g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=rXosxoIm; 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-c513b40eab3si2136078766b.174.2026.11.30.10.48.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:48:33 -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=rXosxoIm; 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=xgLAUUsEzdHh4+rBuW2IGtJpzZAmT+NRg85Cmz1rGh4=; b=rXosxoImwhn3 oADvF3CN+cOUuoMxzchHRFK0742szENs8TYTygr1CyDvSOAzjng6kMV0bklgBdfQpLCilWhIKWcpN IWppiQ7hmrGEfo+3DtNvnS/pmu6NIcgFqjKSpwZKa6r8hNbFIJ8ggmJEdAUH5k1Yq8XhhOl+MUL4N VtLrvQ1oNYJ1r1IwRBTUQs7bwtZ29vQM+yctwqXHR4YaKRnCsd//2zYmpYFzrxZPeorQmaLdG03vF aQmBQ7Eng93/cfSoxf+YMSB/y+PeULLeg7iNx2X2Hml1btSUChnbmQ5OsYfvt82WjbRHHQ9TaigsE /aolvApjtYR1jj3nyQuzWg==; 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 1xY6QA-001tKJ-0J; Mon, 30 Nov 2026 19:48:24 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Mon, 30 Nov 2026 20:45:52 +0200 Message-ID: <20261130184822.2743885-8-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130184822.2743885-1-eva.kurchatova@virtuozzo.com> References: <20261130184822.2743885-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 7/8] 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 --- 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 156467ab4384..dedbf38535db 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1511,17 +1511,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