From: Jon Maloy <jmaloy@redhat.com>
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 [thread overview]
Message-ID: <20261202202103.2840787-1-jmaloy@redhat.com> (raw)
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 <jmaloy@redhat.com>
---
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
reply other threads:[~2026-12-02 20:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202202103.2840787-1-jmaloy@redhat.com \
--to=jmaloy@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).