public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] tcp_buf: Always reserve slot for possible duplicate ACK flag in the same batch
@ 2026-11-24  2:41 Stefano Brivio
  2026-11-24  7:42 ` Laurent Vivier
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2026-11-24  2:41 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier, Jon Maloy

To avoid the risk of splitting two repeated ACKs, the second one being
a duplicate one, onto different batches, as it might significantly
worsen recovery time using fast retransmits, we don't check, in
tcp_buf_send_flag(), if we need to flush the current batch of frames
before we can append a duplicate ACK flag.

So we originally kept one reserved slot at the end of it: for example,
tcp_buf_send_flag() calls tcp_payload_flush() if we have less than two
free slots.

However, with the merging of data and flags buffers, not all the
conditions under which we call tcp_payload_flush() were updated:
tcp_data_to_tap() and tcp_buf_data_from_sock() could return without
ensuring that an extra free slot would be available for a duplicate
ACK flag.  If this happens, and we coincidentally append a duplicate
ACK flag to the batch right after a call to those functions, we'll
crash (reliably) in tcp_buf_send_flag().

Fix those two paths to also reserve one extra slot for duplicate
ACK flags.

Note that, recently, https://bugs.passt.top/show_bug.cgi?id=224
raised some compliance issues with RFC 5681, so we might need to
reserve more slots once we implement full compliance, and probably,
at that point, it would make more sense to consider a different
approach, instead of wasting all that space.

Analysed-by: Laurent Vivier <lvivier@redhat.com>
Fixes: 78da088f7bab ("tcp: unify payload and flags l2 frames array")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tcp_buf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tcp_buf.c b/tcp_buf.c
index ee8c7ce..0780a32 100644
--- a/tcp_buf.c
+++ b/tcp_buf.c
@@ -309,7 +309,7 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn,
 
 	tcp_l2_buf_pad(iov);
 
-	if (++tcp_payload_used > TCP_FRAMES_MEM - 1)
+	if (++tcp_payload_used > TCP_FRAMES_MEM - 2)
 		tcp_payload_flush(c, now);
 }
 
@@ -352,7 +352,7 @@ int tcp_buf_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn,
 		return -1;
 	}
 
-	if (tcp_payload_used + fill_bufs > TCP_FRAMES_MEM) {
+	if (tcp_payload_used + fill_bufs > TCP_FRAMES_MEM - 1) {
 		tcp_payload_flush(c, now);
 
 		/* Silence Coverity CWE-125 false positive */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tcp_buf: Always reserve slot for possible duplicate ACK flag in the same batch
  2026-11-24  2:41 [PATCH] tcp_buf: Always reserve slot for possible duplicate ACK flag in the same batch Stefano Brivio
@ 2026-11-24  7:42 ` Laurent Vivier
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Vivier @ 2026-11-24  7:42 UTC (permalink / raw)
  To: Stefano Brivio, passt-dev; +Cc: Jon Maloy

On 11/24/26 03:41, Stefano Brivio wrote:
> To avoid the risk of splitting two repeated ACKs, the second one being
> a duplicate one, onto different batches, as it might significantly
> worsen recovery time using fast retransmits, we don't check, in
> tcp_buf_send_flag(), if we need to flush the current batch of frames
> before we can append a duplicate ACK flag.
> 
> So we originally kept one reserved slot at the end of it: for example,
> tcp_buf_send_flag() calls tcp_payload_flush() if we have less than two
> free slots.
> 
> However, with the merging of data and flags buffers, not all the
> conditions under which we call tcp_payload_flush() were updated:
> tcp_data_to_tap() and tcp_buf_data_from_sock() could return without
> ensuring that an extra free slot would be available for a duplicate
> ACK flag.  If this happens, and we coincidentally append a duplicate
> ACK flag to the batch right after a call to those functions, we'll
> crash (reliably) in tcp_buf_send_flag().
> 
> Fix those two paths to also reserve one extra slot for duplicate
> ACK flags.
> 
> Note that, recently, https://bugs.passt.top/show_bug.cgi?id=224
> raised some compliance issues with RFC 5681, so we might need to
> reserve more slots once we implement full compliance, and probably,
> at that point, it would make more sense to consider a different
> approach, instead of wasting all that space.
> 
> Analysed-by: Laurent Vivier <lvivier@redhat.com>
> Fixes: 78da088f7bab ("tcp: unify payload and flags l2 frames array")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> ---
>   tcp_buf.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tcp_buf.c b/tcp_buf.c
> index ee8c7ce..0780a32 100644
> --- a/tcp_buf.c
> +++ b/tcp_buf.c
> @@ -309,7 +309,7 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn,
>   
>   	tcp_l2_buf_pad(iov);
>   
> -	if (++tcp_payload_used > TCP_FRAMES_MEM - 1)
> +	if (++tcp_payload_used > TCP_FRAMES_MEM - 2)
>   		tcp_payload_flush(c, now);
>   }
>   
> @@ -352,7 +352,7 @@ int tcp_buf_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn,
>   		return -1;
>   	}
>   
> -	if (tcp_payload_used + fill_bufs > TCP_FRAMES_MEM) {
> +	if (tcp_payload_used + fill_bufs > TCP_FRAMES_MEM - 1) {
>   		tcp_payload_flush(c, now);
>   
>   		/* Silence Coverity CWE-125 false positive */


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24  2:41 [PATCH] tcp_buf: Always reserve slot for possible duplicate ACK flag in the same batch Stefano Brivio
2026-11-24  7:42 ` Laurent Vivier

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).