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.129.124]) by passt.top (Postfix) with ESMTPS id 3B7BF5A0275 for ; Wed, 02 Dec 2026 21:21:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796242869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NGQ0LHYa7yB+R73x2cRemmXkI/i1KSjWzaL4bGAwKbM=; b=YzjNEcBobnKf84EnRA2pJyevcjt0DSCBDqhz1kxZkYKF4keJAGKWhkW9sCjGcHLugFt4va R84t71J0sDZt5P86l8fdBZy0roXiH7Z8MZN6ICIxLhTQBShyFuNd9+OV/RcMaHDf9YVO9r blVkBKJ0+aZRVpJO+Du17TDlCEtnEy8= X-MC-Rep: binary re single Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-313-NHQCLRhrNnKUJliEkLum6g-1; Wed, 2 Dec 2026 20:21:06 +0000 X-MC-Unique: NHQCLRhrNnKUJliEkLum6g-1 X-Mimecast-MFC-AGG-ID: NHQCLRhrNnKUJliEkLum6g_1796242865 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33B69195C5A0 for ; Wed, 2 Dec 2026 20:21:05 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 66E92300039D; Wed, 2 Dec 2026 20:21:04 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH] tcp: Retransmit the same SYN or SYN-ACK on handshake timeout Date: Wed, 2 Dec 2026 15:21:03 -0500 Message-ID: <20261202202103.2840787-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5ZSyQ-1VmKGyuHrm8zLPhoN7WCrOkZb9rvtSXriGYmw_1796242865 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: CI2XXMC5OKMZK5WA3SOECP3H4WQENVFJ X-Message-ID-Hash: CI2XXMC5OKMZK5WA3SOECP3H4WQENVFJ 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 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: Commit 0e8df13c96be ("tcp: Resend SYN for inbound connections") lets tcp_timer_handler() retry the handshake for connections that are taking too long to establish, by sending a new, bare SYN at each retry. However, this approach has two issues: - For connections initiated by the guest (TAP_SYN_RCVD), we send a SYN-ACK, not a SYN, so the retry carries the wrong flags, and lacks the ACK - As tcp_prepare_flags() advances seq_to_tap for every SYN we send, every retry uses a different sequence number, and, once the handshake completes, we start sending data from the ISN plus the number of retries, instead of ISN + 1 If the guest acknowledges our original SYN-ACK (or SYN) after one or more retries, for example because the ACK was held in a queue, we send data with sequence numbers shifted by the number of retries, and, once the retransmission timer rewinds to the acknowledged sequence, the same data again, so that the guest assembles a corrupted stream. Retransmit what we originally sent instead: a SYN-ACK if the guest initiated the connection, a SYN otherwise, and reset seq_to_tap to the initial sequence number first, which is still stored in seq_ack_from_tap at this point. If the guest initiated the connection, i.e. the TAP_SYN_RCVD flag is set, we set the ACK flag in each retry, otherwise not. In both cases, we rewind the sequence number to ISN before retransmitting. Link: https://bugs.passt.top/show_bug.cgi?id=229 Fixes: 0e8df13c96be ("tcp: Resend SYN for inbound connections") Signed-off-by: Jon Maloy --- tcp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tcp.c b/tcp.c index 409f4ce1..7dfb1490 100644 --- a/tcp.c +++ b/tcp.c @@ -2729,8 +2729,19 @@ void tcp_timer_handler(const struct ctx *c, union epoll_ref ref, flow_dbg(conn, "handshake timeout"); tcp_rst(c, conn, now); } else { + int flags = SYN; + flow_trace(conn, "SYN timeout, retry"); - if (tcp_send_flag(c, conn, SYN, now)) { + + /* Retransmit what we sent: a SYN-ACK if the + * guest initiated the connection, a SYN + * otherwise. Rewind to ISN at each retry. + */ + if (conn->events & TAP_SYN_RCVD) + flags |= ACK; + conn->seq_to_tap = conn->seq_ack_from_tap; + + if (tcp_send_flag(c, conn, flags, now)) { tcp_rst(c, conn, now); return; } -- 2.56.1