aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorJon Maloy <jmaloy@redhat.com>2026-12-02 15:21:03 -0500
committerStefano Brivio <sbrivio@redhat.com>2026-12-02 23:00:56 +0100
commitf8f340650247e97b0633a33cdb08e20f2880b36b (patch)
treee5164eb04861e8e32f438f4cd83846bea12d10e9
parentf4c69b552ee9a49d322ee566c43e771c56121137 (diff)
downloadpasst-f8f340650247e97b0633a33cdb08e20f2880b36b.tar
passt-f8f340650247e97b0633a33cdb08e20f2880b36b.tar.gz
passt-f8f340650247e97b0633a33cdb08e20f2880b36b.tar.bz2
passt-f8f340650247e97b0633a33cdb08e20f2880b36b.tar.lz
passt-f8f340650247e97b0633a33cdb08e20f2880b36b.tar.xz
passt-f8f340650247e97b0633a33cdb08e20f2880b36b.tar.zst
passt-f8f340650247e97b0633a33cdb08e20f2880b36b.zip
tcp: Retransmit the same SYN or SYN-ACK on handshake timeoutHEADmaster
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. Reported-by: Fumin <awawfumin@gmail.com> Link: https://bugs.passt.top/show_bug.cgi?id=229 Fixes: 0e8df13c96be ("tcp: Resend SYN for inbound connections") Signed-off-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tcp.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/tcp.c b/tcp.c
index ca0c185..f55cf26 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2724,8 +2724,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;
}