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 B2DCA5A026E for ; Tue, 01 Dec 2026 09:23:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796113389; 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: in-reply-to:in-reply-to:references:references; bh=BYZueryzD42X5lldP6rVUPqOU7gAEXt46conNCkWruw=; b=E8CINfLW3lC+d+8LC0qtFRTuJUKKr4JQfiK0fDFVuYWrXB53AJ/+4tkkpXIpt86nVFvzQY SAx7FvxrQDzOOY0P25L6olJ9HrQhlBo3jxfF4zDISctRW8ARx0ImPzKUdRWMG76Nhyyl3S xi5ollshXhYaWUn2GHi1fje229iIK9Q= X-MC-Rep: binary re single Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-GzUmCfMuOmGlvvMURU6UeQ-1; Tue, 1 Dec 2026 08:23:08 +0000 X-MC-Unique: GzUmCfMuOmGlvvMURU6UeQ-1 X-Mimecast-MFC-AGG-ID: GzUmCfMuOmGlvvMURU6UeQ_1796113387 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4a1fdde384cso83477285e9.3 for ; Tue, 01 Dec 2026 00:23:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796113387; x=1796718187; h=date:content-transfer-encoding:content-type:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content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scIUWFJBfl+/T9+DEEu8njpVFGuEEftPCPMF4= X-Received: by 2002:a05:600c:3ba5:b0:4b0:a307:46f8 with SMTP id 5b1f17b1804b1-4bb8880f29bmr791735965e9.10.1796113386515; Tue, 01 Dec 2026 00:23:06 -0800 (PST) X-Received: by 2002:a05:600c:3ba5:b0:4b0:a307:46f8 with SMTP id 5b1f17b1804b1-4bb8880f29bmr791735045e9.10.1796113385864; Tue, 01 Dec 2026 00:23:05 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb8538b09bsm1823245165e9.4.2026.12.01.00.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 00:23:05 -0800 (PST) From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH] tcp: Handle data and FIN in TAP_SYN_RCVD like in established connections Message-ID: <20261201092303.700538ea@elisabeth> In-Reply-To: <20261127200124.764292-1-jmaloy@redhat.com> References: <20261127200124.764292-1-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Tue, 01 Dec 2026 09:23:04 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: HwZ4DYaK2QyYKkkfFeFriKS-1zVAHR4byjSJgL-67KE_1796113387 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: PARORS6QM7ZARS7CONTBYDWCRC2ISQHK X-Message-ID-Hash: PARORS6QM7ZARS7CONTBYDWCRC2ISQHK X-MailFrom: sbrivio@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: passt-dev@passt.top, "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: On Fri, 27 Nov 2026 15:01:24 -0500 Jon Maloy wrote: > 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 Applied, thanks everybody for reporting and fixing this! Checking again RFC 9293 after this report, I start thinking that there's an unreachable situation described in 3.10.7 "SEGMENT ARRIVES". I actually wrote the original implementation before RFC 9293 was published, but the same reasoning applies to RFC 793. Using RFC 9293 for clarity, section 3.10.7.4 "Other States" reports, as eighth step: https://www.rfc-editor.org/info/rfc9293/#section-3.10.7.4-2.8.1 [...] - If the FIN bit is set, signal the user "connection closing" and return any pending RECEIVEs with same message, advance RCV.NXT over the FIN, and send an acknowledgment for the FIN. Note that FIN implies PUSH for any segment text not yet delivered to the user. o SYN-RECEIVED STATE o ESTABLISHED STATE + Enter the CLOSE-WAIT state. [...] and SYN-RECEIVED --FIN--> CLOSE-WAIT is the transition I intended to implement. However, the fifth step, if ACK is set, and we are in the SYN-RECEIVED state: https://www.rfc-editor.org/info/rfc9293/#section-3.10.7.4-2.5.2.2.2.2.1 says: If SND.UNA < SEG.ACK =< SND.NXT, then enter ESTABLISHED state (we should probably check the sequence explicitly here, but let's ignore that for a moment). So at that point we must always be in ESTABLISHED state, unless ACK is not set, in which case: https://www.rfc-editor.org/info/rfc9293/#section-3.10.7.4-2.5.2.1 if the ACK bit is off, drop the segment and return So I don't see a way to reach that eighth step in SYN-RECEIVED state: - if we get a segment with ACK set, we'll switch to ESTABLISHED in step five - and if ACK is not set, we return at step five anyway ...which is rather weird. Perhaps we should submit an erratum. I see a similar one (https://errata.rfc-editor.org/eid8805/) currently on hold, but that one refers to FIN-WAIT-1 instead. I'll need to check again in a bit with fresh eyes, and submit it if it makes sense. Anyway, with this change, we'll go (at least conceptually) through ESTABLISHED in any case, which appears to be correct. Back to the sequence check and that RFC 5961 mention in steps five and four: _perhaps_ we should implement that at some point, even though that kind of attack is not very relevant for us (if at all), because the implementation is exposed to a single guest (at least for the moment). That's something we should definitely look into if we ever get to support multiple guests/containers, though. -- Stefano