From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 541BE5A026E for ; Fri, 27 Nov 2026 21:01:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795809694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1Q7U+hREnqyJySoPKKT44C0X0C10fYCfTnSMaJO4nBY=; b=FYkJh22tLgJX69aUu/M/yvhPyyvoFKR9bWjv0rmPfFGCX4YFHtfSb3nVyrVbs8fqbhKh2W Q5TZtgJzW0YyS+znRcSaoSaXfBMTsFUyvHMXyP6Zj34AC2H5cfQFrDU9jJYjTSzQOu57ey V2nQ/xP2mqj7yslKrZa2kT0SQ8Db6SA= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-FUUy94NkMlW8yzcjhYreBg-1; Fri, 27 Nov 2026 20:01:30 +0000 X-MC-Unique: FUUy94NkMlW8yzcjhYreBg-1 X-Mimecast-MFC-AGG-ID: FUUy94NkMlW8yzcjhYreBg_1795809689 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 45BFF1800366; Fri, 27 Nov 2026 20:01:28 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BBAD6195604E; Fri, 27 Nov 2026 20:01:25 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH] tcp: Handle data and FIN in TAP_SYN_RCVD like in established connections Date: Fri, 27 Nov 2026 15:01:24 -0500 Message-ID: <20261127200124.764292-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: dZRt3C4ae18RS43VuNoUG7caGZquCO3xwb6N6O0MMOU_1795809689 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: I5VQ6XXFI5DOSLOJCUY4RCJZGY67VAPV X-Message-ID-Hash: I5VQ6XXFI5DOSLOJCUY4RCJZGY67VAPV X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: "Zhenrong (Daniel) Gu" , Xing Feng , Peng Zhang X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In tcp_tap_handler(), the TAP_SYN_RCVD branch handles the segment completing the handshake from the guest, but it also handles a FIN in the same segment on its own, without checking that its sequence is the expected one, or that the segment carries no data: on a FIN, we increase seq_from_tap, shut down the socket for writing, send an ACK, and return. If the FIN is out of order, for example because it overtook the data preceding it, we acknowledge data we never received, the server gets an EOF without any data, and once the data arrives, we reset the connection. If the FIN comes together with data, the data is lost. A FIN without ACK is also accepted, as we only check for the ACK flag afterwards. In both cases, we don't set TAP_FIN_RCVD either. Further, if the segment is the last one in a batch, we return right after processing the handshake, without looking at any data it might carry: the data is neither forwarded nor acknowledged, and the guest needs to retransmit it. Check for the ACK flag before considering the connection established, and only return early for a pure ACK: otherwise, let tcp_data_from_tap() handle data and FIN, which already checks that the FIN is in sequence, and sets TAP_FIN_RCVD, so that we shut down the socket once all the data was forwarded. With the reproducer attached to the bug report, which opens 100 connections through pasta with reordering on the tap interface, 34 connections end up with an empty EOF without this change, and none with it. Link: https://bugs.passt.top/show_bug.cgi?id=226 Reported-by: Zhenrong (Daniel) Gu Reported-by: Xing Feng Reported-by: Peng Zhang Signed-off-by: Jon Maloy --- tcp.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/tcp.c b/tcp.c index 409f4ce1..8b249dd9 100644 --- a/tcp.c +++ b/tcp.c @@ -2391,37 +2391,22 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, if (th->syn && !th->ack && !th->fin) return packet_next(p, idx) - idx; - if (!(conn->events & TAP_SYN_ACK_SENT)) + if (!(conn->events & TAP_SYN_ACK_SENT) || !th->ack) goto reset; conn_event(c, conn, ESTABLISHED, now); if (tcp_set_peek_offset(conn, 0, now)) goto reset; - if (th->fin) { - conn->seq_from_tap++; - - if (shutdown(conn->sock, SHUT_WR) < 0) { - flow_warn_perror_ratelimit(conn, now, - "shutdown() failed"); - goto reset; - } - - if (tcp_send_flag(c, conn, ACK, now)) - goto reset; - - conn_event(c, conn, SOCK_FIN_SENT, now); - - return packet_next(p, idx) - idx; - } - - if (!th->ack) - goto reset; - if (tcp_tap_window_update(c, conn, ntohs(th->window), now)) tcp_data_from_sock(c, conn, now); - if (packet_next(p, idx) == p->count) + /* Pure ACK completing the handshake, and nothing else to + * process: otherwise, data and FIN, even if they're out of + * order, are handled by tcp_data_from_tap() below + */ + if (packet_next(p, idx) == p->count && !th->fin && + !tcp_packet_data_len(th, l4len)) return packet_next(p, idx) - idx; } -- 2.56.1