From 6569a6f6c94e656a04f77132f853666550b744c7 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 1 Dec 2026 02:04:29 +0100 Subject: tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure 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 --- 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. */ -- cgit v1.2.3