aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorJon Maloy <jmaloy@redhat.com>2026-11-27 15:01:24 -0500
committerStefano Brivio <sbrivio@redhat.com>2026-12-01 09:23:34 +0100
commit14b5f2b4fb561efee7e2bad55c4014c8ca76d7db (patch)
tree3f12b38fa1300c604e58d20a472e7a7ebad4512d
parent2ac075a62864822f109b766fd474eeb9274d7431 (diff)
downloadpasst-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.tar
passt-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.tar.gz
passt-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.tar.bz2
passt-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.tar.lz
passt-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.tar.xz
passt-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.tar.zst
passt-14b5f2b4fb561efee7e2bad55c4014c8ca76d7db.zip
tcp: Handle data and FIN in TAP_SYN_RCVD like in established connections
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 <zrgu@stu.xjtu.edu.cn> Reported-by: Xing Feng <xingfeng@stu.xjtu.edu.cn> Reported-by: Peng Zhang <p-zhang@xjtu.edu.cn> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
-rw-r--r--tcp.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/tcp.c b/tcp.c
index 07a5e9c..15a41c5 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2393,37 +2393,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;
}