public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] icmp: Discard echo replies too big to be forwarded to the guest
@ 2026-11-23  0:27 Stefano Brivio
  0 siblings, 0 replies; only message in thread
From: Stefano Brivio @ 2026-11-23  0:27 UTC (permalink / raw)
  To: passt-dev; +Cc: Stuart Thomas

From: Stuart Thomas <Stuart.Thomas@triageforge.co.uk>

Original patch and report by Stuart Thomas, commit message rewritten
for clarity, with added details, after further investigation.

Stuart reports that, even though the data length of ICMP and ICMPv6
echo requests we forward from the guest is limited by the maximum
guest MTU (see also https://bugs.passt.top/show_bug.cgi?id=55), and
even though RFC 792 mandates that the echo reply returns the original
data as received in the request, it's actually possible, at least
using local sockets, to send back a (reassembled) reply that's bigger
than the original request.

To cover that case, we need to clamp the size of the replies we relay
via icmp_sock_handler(), because, otherwise, tap_icmp4_send() and
tap_icmp6_send() could try to exceed the available buffer by 34 bytes
for IPv4 (ETH_HLEN plus IP header) or 54 bytes for IPv6 (ETH_HLEN plus
IPv6 header).  This is actually prevented by __memcpy_chk() to a
known size object, which leads to a reliable abort, and, even if
somebody happens to disable FORTIFY_SOURCE guards in their builds,
this would hit the stack protector, resulting again in termination.

Regardless of this, it's probably wiser to discard the reply and
continue, as this condition is unlikely to indicate a situation where
we can't proceed with regular functionality and a restart would help
to recover from.

Only the guest can trigger this condition by sending a request to a
particular peer, set up to reply with an invalid message, with the
sole outcome of sabotaging its own connectivity (which can anyway be
done in more direct ways), so this is a robustness issue rather than
a security problem.

As alternative fixes, we considered:

- truncating the reply, but this wouldn't really fit our network
  transparency goals, and on top of that we would need to recalculate
  the checksum, which would mean substantially modifying ICMP messages
  even further

- dropping any reply that exceeds (with headers) the link MTU, instead
  of letting the guest eventually do that.  This would be more correct
  in some sense, but also less transparent, and would make things
  harder to debug in case any problem in this sense is suspected

Simply drop the oversized reply instead.  As Stuart already noted, we
are not able to forward them (intact) anyway.

We would like to thank Stuart Thomas for the detailed investigation,
for the comprehensive report, for the patch, and for sharing his
results in a clear, honest way.

Reported-by: Stuart Thomas <Stuart.Thomas@triageforge.co.uk>
Signed-off-by: Stuart Thomas <Stuart.Thomas@triageforge.co.uk>
Fixes: 1d807fc720bd ("passt: Introduce ICMP echo proxy")
[sbrivio: commit message]
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 icmp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/icmp.c b/icmp.c
index 0fe2366..7045d5f 100644
--- a/icmp.c
+++ b/icmp.c
@@ -94,6 +94,7 @@ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
 		struct icmphdr *ih4 = (struct icmphdr *)buf;
 
 		if (sr.sa_family != AF_INET || (size_t)n < sizeof(*ih4) ||
+		    (size_t)n > USHRT_MAX - ETH_HLEN - sizeof(struct iphdr) ||
 		    ih4->type != ICMP_ECHOREPLY)
 			goto unexpected;
 
@@ -104,6 +105,7 @@ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
 		struct icmp6hdr *ih6 = (struct icmp6hdr *)buf;
 
 		if (sr.sa_family != AF_INET6 || (size_t)n < sizeof(*ih6) ||
+		    (size_t)n > USHRT_MAX - ETH_HLEN - sizeof(struct ipv6hdr) ||
 		    ih6->icmp6_type != ICMPV6_ECHO_REPLY)
 			goto unexpected;
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23  0:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23  0:27 [PATCH] icmp: Discard echo replies too big to be forwarded to the guest 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).