public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH 0/3] Fix Coverity Scan warnings triggered by recent commits
@ 2026-12-01  8:24 Stefano Brivio
  2026-12-01  8:24 ` [PATCH 1/3] tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure Stefano Brivio
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-12-01  8:24 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier, Jon Maloy

Coverity started reporting the issue fixed in 1/3 with 6637c202f261
("tap: Explicitly drop outbound IPv6 fragments, warn about them") but
only with a given combination of recent commits, for some reason.

Patch 2/3 makes that kind of error (harmless, in this case) less
likely.

Patch 3/3 takes care of a warning on pre-existing code, that only
appeared now due to a related commit.

Stefano Brivio (3):
  tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure
  icmp, tcp, udp: Change Layer-4 protocol handlers to return unsigned
  fwd: Check return value of lineread_get() for /proc/net entries before
    proceeding

 fwd.c  |  6 +++++-
 icmp.c |  7 ++++---
 icmp.h |  7 ++++---
 tcp.c  | 11 ++++++-----
 tcp.h  |  7 ++++---
 udp.c  |  8 ++++----
 udp.h  |  8 ++++----
 7 files changed, 31 insertions(+), 23 deletions(-)

-- 
2.43.0


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

* [PATCH 1/3] tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure
  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
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-12-01  8:24 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier, Jon Maloy

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


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

* [PATCH 2/3] icmp, tcp, udp: Change Layer-4 protocol handlers to return unsigned
  2026-12-01  8:24 [PATCH 0/3] Fix Coverity Scan warnings triggered by recent commits Stefano Brivio
  2026-12-01  8:24 ` [PATCH 1/3] tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure Stefano Brivio
@ 2026-12-01  8:24 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-12-01  8:24 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier, Jon Maloy

...to avoid embarrassing mistakes like the one fixed by the previous
commit: they are always supposed to return a count of consumed
packets, and handle protocol errors themselves.

Note that, strictly speaking, those should all return size_t instead
of unsigned int, but changing tcp_tap_handler() to return size_t
triggers something that looks like a false positive in Coverity Scan
which I still need to investigate.  Just fix the signedness for the
moment being.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 icmp.c | 7 ++++---
 icmp.h | 7 ++++---
 tcp.c  | 7 ++++---
 tcp.h  | 7 ++++---
 udp.c  | 8 ++++----
 udp.h  | 8 ++++----
 6 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/icmp.c b/icmp.c
index 7045d5f..25eec53 100644
--- a/icmp.c
+++ b/icmp.c
@@ -249,9 +249,10 @@ cancel:
  *
  * Return: count of consumed packets (always 1, even if malformed)
  */
-int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
-		     const void *saddr, const void *daddr,
-		     struct iov_tail *data, const struct timespec *now)
+unsigned int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
+			      const void *saddr, const void *daddr,
+			      struct iov_tail *data,
+			      const struct timespec *now)
 {
 	struct iovec iov[MAX_IOV_ICMP];
 	struct icmp_ping_flow *pingf;
diff --git a/icmp.h b/icmp.h
index 8b8fa40..55569c2 100644
--- a/icmp.h
+++ b/icmp.h
@@ -15,9 +15,10 @@ struct icmp_ping_flow;
 
 void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
 		       const struct timespec *now);
-int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
-		     const void *saddr, const void *daddr,
-		     struct iov_tail *data, const struct timespec *now);
+unsigned int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
+			      const void *saddr, const void *daddr,
+			      struct iov_tail *data,
+			      const struct timespec *now);
 void icmp_init(void);
 
 
diff --git a/tcp.c b/tcp.c
index 481cdfb..ca0c185 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2313,9 +2313,10 @@ static void tcp_rst_no_conn(const struct ctx *c, int af,
  *
  * Return: count of consumed packets
  */
-int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
-		    const void *saddr, const void *daddr, uint32_t flow_lbl,
-		    const struct pool *p, int idx, const struct timespec *now)
+unsigned int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
+			     const void *saddr, const void *daddr,
+			     uint32_t flow_lbl, const struct pool *p, int idx,
+			     const struct timespec *now)
 {
 	struct tcp_tap_conn *conn;
 	struct tcphdr th_storage;
diff --git a/tcp.h b/tcp.h
index b68f882..6acbafb 100644
--- a/tcp.h
+++ b/tcp.h
@@ -24,9 +24,10 @@ void tcp_listen_handler(const struct ctx *c, union epoll_ref ref,
 			const struct timespec *now);
 void tcp_sock_handler(const struct ctx *c, union epoll_ref ref,
 		      uint32_t events, const struct timespec *now);
-int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
-		    const void *saddr, const void *daddr, uint32_t flow_lbl,
-		    const struct pool *p, int idx, const struct timespec *now);
+unsigned int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
+			     const void *saddr, const void *daddr,
+			     uint32_t flow_lbl, const struct pool *p, int idx,
+			     const struct timespec *now);
 int tcp_init(struct ctx *c);
 void tcp_defer_handler(struct ctx *c, const struct timespec *now);
 
diff --git a/udp.c b/udp.c
index a7fcc4d..7966079 100644
--- a/udp.c
+++ b/udp.c
@@ -1016,10 +1016,10 @@ fail:
  *
  * #syscalls sendmmsg
  */
-int udp_tap_handler(const struct ctx *c, uint8_t pif,
-		    sa_family_t af, const void *saddr, const void *daddr,
-		    uint8_t ttl, const struct pool *p, int idx,
-		    const struct timespec *now)
+unsigned int udp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
+			     const void *saddr, const void *daddr, uint8_t ttl,
+			     const struct pool *p, int idx,
+			     const struct timespec *now)
 {
 	const struct flowside *toside;
 	struct mmsghdr mm[UIO_MAXIOV];
diff --git a/udp.h b/udp.h
index b50283e..472b75d 100644
--- a/udp.h
+++ b/udp.h
@@ -15,10 +15,10 @@ void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref,
 			     uint32_t events, const struct timespec *now);
 void udp_sock_handler(const struct ctx *c, union epoll_ref ref,
 		      uint32_t events, const struct timespec *now);
-int udp_tap_handler(const struct ctx *c, uint8_t pif,
-		    sa_family_t af, const void *saddr, const void *daddr,
-		    uint8_t ttl, const struct pool *p, int idx,
-		    const struct timespec *now);
+unsigned int udp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
+			     const void *saddr, const void *daddr, uint8_t ttl,
+			     const struct pool *p, int idx,
+			     const struct timespec *now);
 int udp_init(struct ctx *c);
 void udp_update_l2_buf(const unsigned char *eth_d);
 
-- 
2.43.0


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

* [PATCH 3/3] fwd: Check return value of lineread_get() for /proc/net entries before proceeding
  2026-12-01  8:24 [PATCH 0/3] Fix Coverity Scan warnings triggered by recent commits Stefano Brivio
  2026-12-01  8:24 ` [PATCH 1/3] tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure Stefano Brivio
  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 ` Stefano Brivio
  2 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-12-01  8:24 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier, Jon Maloy

Not really a functional issue as we would detect malformed entries in
/proc/net files in the loop just after this point, but Coverity Scan
realised, after cfca8d1daa4b ("conf: Follow changes to the host
nameserver used for DNS forwarding"), that we don't check the return
value of lineread_get() in procfs_scan_listen().

Check it and add a separate warning if we can't read even a single
line from the file.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 fwd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fwd.c b/fwd.c
index add01c0..b2dc074 100644
--- a/fwd.c
+++ b/fwd.c
@@ -652,7 +652,11 @@ static void procfs_scan_listen(int fd, unsigned int lstate, uint8_t *map)
 	}
 
 	lineread_init(&lr, fd);
-	lineread_get(&lr, &line); /* throw away header */
+	if (lineread_get(&lr, &line) <= 0) { /* throw away header */
+		warn("Failed to read /proc/net file");
+		return;
+	}
+
 	while (lineread_get(&lr, &line) > 0) {
 		/* != 2 if conversion fails */
 		/* NOLINTNEXTLINE(bugprone-unchecked-string-to-number-conversion,cert-err34-c) */
-- 
2.43.0


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

end of thread, other threads:[~2026-12-01  8:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  8:24 [PATCH 0/3] Fix Coverity Scan warnings triggered by recent commits Stefano Brivio
2026-12-01  8:24 ` [PATCH 1/3] tcp: Fix return value of tcp_tap_handler() on SO_PEEK_OFF failure Stefano Brivio
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

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