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 4B91F80031 for ; Tue, 1 Dec 2026 15:39:37 +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 6B1FcMtn020111; Tue, 1 Dec 2026 18:38:23 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1FcMtn020111 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="X1ul4rSy" 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 6B1FbtFO019981 (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 6B1FbtFO019981 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-c40aa03ded8so218970666b.2 for ; Tue, 01 Dec 2026 07:37:55 -0800 (PST) X-Gm-Message-State: APuU4Z+AiFPnbPxeYU6HKMufPpXFcbHqV0+SHfv2NqLC8VWeFpFy46MQ A9lMPUMPa3E7bZCNa3Gd0n8cUcSLcFZi9LVnFdmjXN+OfllNg1A0gXm1DmDsvHRn4iP47RoCOcH iEvgEVBNotVvv6HvRpNU41LyU3Att6JXhZhMu21d3q2Q4g10SJnb6PQ== X-Gm-Gg: AZFdTZeVxflFgSW5DRZIqDWF8LsdyjmgJSG84869J5U5BxfeNYewwhX9Gd8r/VSxKZg o802y4ZRSOGEtdrgVu9gKs7yTZ6gB9MIq7vj5W6RWDP0FOIPwWKthb9M64TpLSpZh8tFVR/whLs 4YOUwUIGo9jpTYwtBY5QIZXtOc07+2AMgJsZCg5mEjy4Hpd9XpGBfuFsjBS7euqhPoge+yYRkU0 f9iMmpo4c0zzRSx9cms+GQ2FUhDpRF+Ai3+VlZEXBU7+7XfQ7R996EHDZzUXrsfE7pEvmNhY6K+ Ry2/dBEw2oeK138MXUjeZ4GMR/V8saeLQqaCD/AkGY8gIAGm+tJV5xNkJTxmpwJsQ6GrRZd21Fm dkMum2YbfIfLVC0BRNbGfjk6d X-Received: by 2002:a17:906:d206:b0:c2d:bae5:27d9 with SMTP id a640c23a62f3a-c513acb17c5mr2525562066b.46.1796139474716; Tue, 01 Dec 2026 07:37:54 -0800 (PST) X-Received: by 2002:a17:906:d206:b0:c2d:bae5:27d9 with SMTP id a640c23a62f3a-c513acb17c5mr2525560266b.46.1796139474231; Tue, 01 Dec 2026 07:37:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796139474; cv=none; d=google.com; s=arc-20260327; b=aZSTyMdEEKJGYQF5gam9kxgoAMT31zzknsu/7n14NyrpgCGjBMQKub0qFKuuudnJzc Ir70SIJHNLfQcq2yj3FiAgnHPqdSLr+2aIlxbHdZcH9BEyvqJePUGRzAV+hQjxa+jVBg d2qwEiTigt2rdoF/BVo5LFLC/YfH0oWuX62z68t2cbotgKfBGG2a3EIuh0NnniRi4H7P PjSCnAZigBYGViLj0pObRKUyvOKpqtI5Odw+eU7qVrl2Rv4zXsev5IK4W6q3u1dHHPq4 SnK6d+3Ilfyo0T5HLfU1NGKUB6e676nvvvPoiQXEfg65feWvzO8PfexO0R4B5YjoE7KW b1+A== 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=jpnnaH7QWOR7/mzsRMherlD+jYTHl5v6kzsh7pxrhmI=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=d6f7WkSQ3/d1/kcQ3hESOpdhI33AA7wK/cIoy9OpCDrZ0vIqqPfWxio4KkeoeaaUwR FM+i2JFyICyFcLID6rGCfNG/vOIkrOKYQB39a8d6xYuHTg1OI4inqx6kNA4l/wxKUMVi 3sugc31lbC6SVnx1DeowLXW3FWQ0MFD7mg5jKJSiiTdPWbazThfXxFLAFcmp8BLglvXl LmH/4YSesHwn6zFAvsx+Ne0o8w7VUZjghtsqGPISy0ZWx69kJsFQvqc8nm7AptHD+i3s gstiJPrJGtf1t4tK+4JKz4uKIAnCJQ/gLJKRKPMjDNgDn0GUfrq3oZlD9Kv04wTEMzZV DfqQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=X1ul4rSy; 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-c5190c82233si1527299766b.386.2026.12.01.07.37.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:37:54 -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=X1ul4rSy; 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=jpnnaH7QWOR7/mzsRMherlD+jYTHl5v6kzsh7pxrhmI=; b=X1ul4rSyHsLA rvV2RLJWiri0knyy88G8jRsGVjAqgWEDWdHapic/v3/dmXCc70WlBu+TJsKRFH9CCxPjz7RHj/C0h WqrOuG63B92o8eCBWAeibn3xDFWhYcN4DoHgrRVZPo8UIxjIbwuNBGMaRKgK1mTyJO/5d0DkwqS73 WRwjH64O2n7A7WWCNMJNUxGN4baDES8qdW5A2g5nAzGTpY9TiEYJIyuqfhySN+4keXdFHweIHtp9j ZJzPvSKeOyhBgb4tLtAPQr9UQE1NE7br069lYSmDkXTezAWVnE5P4oKoiU/kUpoerV1wrYAe1v3u5 33sui17IUEIEG+apWjo+gQ==; 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 1xYPvB-0081OE-0f; 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:23 +0200 Message-ID: <20261201153749.2872789-9-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 08/15] ms/tcp: purge Fast Open RST queue when listen() fails 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: Eric Dumazet inet_csk_listen_start() moves the socket to TCP_LISTEN before calling ->get_port() and ->hash(). If one of them fails, the socket goes back to TCP_CLOSE without going through inet_csk_listen_stop(). If the socket was a Fast Open listener in a previous life, and was stopped with shutdown(SHUT_RD) or connect(AF_UNSPEC) while an accepted Fast Open child was still in TCP_SYN_RECV state, the request_sock of this child still points to the listener. A valid RST received for this child while the listener is transiently in TCP_LISTEN state makes reqsk_fastopen_remove() queue the request_sock in rskq_rst_head. When listen() fails, for instance with -EADDRINUSE because another SO_REUSEADDR socket started listening on the same port, nothing reclaims it: - __tcp_close(), tcp_disconnect() and tcp_abort() only call inet_csk_listen_stop() for sockets in TCP_LISTEN state. - A later successful listen() overwrites rskq_rst_head in reqsk_queue_alloc(). The request_sock is leaked, together with the reference it holds on the listener. Move the rskq_rst_head purge to a helper, and call it from the inet_csk_listen_start() error path as well, after the socket state has been set back to TCP_CLOSE: reqsk_fastopen_remove() checks sk_state under fastopenq.lock, so it either queued the request before the purge acquires the lock, or does not queue it at all. Reported-by: Sashiko AI review Closes: https://lore.kernel.org/netdev/179450310167.2199510.18107423940014989443@kernel.org/ Fixes: 0536fcc039a8 ("tcp: prepare fastopen code for upcoming listener changes") Signed-off-by: Eric Dumazet Reviewed-by: Hyunwoo Kim Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261114111247.21995-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski (cherry picked from commit 342e62fd34c2674e82bffc89cb5c7091924986d9) Rebase note: conflict in context only. reqsk_queue_alloc(), next to which upstream adds reqsk_fastopen_purge_rst(), is still in net/core/request_sock.c here; d5c539155431 ("inet: move reqsk_queue_alloc() to net/ipv4/inet_connection_sock.c") is not taken. 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 | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index bc4c732946bb..018b9c605c02 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1327,6 +1327,22 @@ static int inet_ulp_can_listen(const struct sock *sk) return 0; } +/* Free all the reqs queued in rskq_rst_head. */ +static void reqsk_fastopen_purge_rst(struct request_sock_queue *queue) +{ + struct request_sock *next, *req; + + 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; + } +} + int inet_csk_listen_start(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); @@ -1360,6 +1376,12 @@ int inet_csk_listen_start(struct sock *sk) } inet_sk_set_state(sk, TCP_CLOSE); + + /* A Fast Open child accepted before a previous shutdown() of this + * listener might have queued its request in rskq_rst_head while + * we were transiently in TCP_LISTEN state. + */ + reqsk_fastopen_purge_rst(&icsk->icsk_accept_queue); return err; } EXPORT_SYMBOL_GPL(inet_csk_listen_start); @@ -1467,7 +1489,7 @@ void inet_csk_listen_stop(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); struct request_sock_queue *queue = &icsk->icsk_accept_queue; - struct request_sock *next, *req; + struct request_sock *req; /* Following specs, it would be better either to send FIN * (and enter FIN-WAIT-1, it is normal close) @@ -1523,16 +1545,7 @@ void inet_csk_listen_stop(struct sock *sk) if (!has_current_bpf_ctx()) cond_resched(); } - /* 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; - } + reqsk_fastopen_purge_rst(queue); WARN_ON_ONCE(sk->sk_ack_backlog); } EXPORT_SYMBOL_GPL(inet_csk_listen_stop); -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel