public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>, Jon Maloy <jmaloy@redhat.com>
Subject: [PATCH 1/3] tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure
Date: Tue,  1 Dec 2026 09:24:33 +0100	[thread overview]
Message-ID: <20261201082435.1302453-2-sbrivio@redhat.com> (raw)
In-Reply-To: <20261201082435.1302453-1-sbrivio@redhat.com>

This can't actually happen with the current kernel implementation of
SO_PEEK_OFF, but still it's rather fragile and obviously wrong:
tcp_tap_handler() should never return negative values, but that's
what the error path for tcp_rewind_seq() actually does.

For some reason, Coverity Scan spotted this only after 6637c202f261
("tap: Explicitly drop outbound IPv6 fragments, warn about them") in
combination with other recent commits.

Instead of -1, return a value corresponding to one consumed packet.

While at it, fix the comment to tcp_data_from_tap() indicating that,
there, -1 is a legitimate return value instead.

Fixes: bde1847960cf ("tcp: Fast re-transmit if half-closed, make TAP_FIN_RCVD path consistent")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tcp.c b/tcp.c
index 15a41c5..481cdfb 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1935,7 +1935,7 @@ static ssize_t tcp_packet_data_len(const struct tcphdr *th, size_t l4len)
  *
  * #syscalls sendmsg
  *
- * Return: count of consumed packets
+ * Return: count of consumed packets, -1 on unrecoverable connection error
  */
 static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
 			     const struct pool *p, int idx,
@@ -2450,7 +2450,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
 				   ntohl(th->ack_seq), conn->seq_to_tap);
 
 			if (tcp_rewind_seq(c, conn, now))
-				return -1;
+				return packet_next(p, idx) - idx;
 		}
 
 		/* An unchanged ACK and window must not restart the timer. */
-- 
2.43.0


  reply	other threads:[~2026-12-01  8:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:24 [PATCH 0/3] Fix Coverity Scan warnings triggered by recent commits Stefano Brivio
2026-12-01  8:24 ` Stefano Brivio [this message]
2026-12-01  8:24 ` [PATCH 2/3] icmp, tcp, udp: Change Layer-4 protocol handlers to return unsigned Stefano Brivio
2026-12-01  8:24 ` [PATCH 3/3] fwd: Check return value of lineread_get() for /proc/net entries before proceeding Stefano Brivio

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=20261201082435.1302453-2-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=jmaloy@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /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).