aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStuart Thomas <Stuart.Thomas@triageforge.co.uk>2026-11-04 00:58:24 +0000
committerStefano Brivio <sbrivio@redhat.com>2026-11-23 00:38:58 +0100
commit9113dc6692f4c37d5d5363e640ee5340612123ea (patch)
treeca94e6daa5451c18e2e6e1e686e166b08c908cf7
parent094211f421e47fb9d72430b228a0ab4a5b1cdb9d (diff)
downloadpasst-9113dc6692f4c37d5d5363e640ee5340612123ea.tar
passt-9113dc6692f4c37d5d5363e640ee5340612123ea.tar.gz
passt-9113dc6692f4c37d5d5363e640ee5340612123ea.tar.bz2
passt-9113dc6692f4c37d5d5363e640ee5340612123ea.tar.lz
passt-9113dc6692f4c37d5d5363e640ee5340612123ea.tar.xz
passt-9113dc6692f4c37d5d5363e640ee5340612123ea.tar.zst
passt-9113dc6692f4c37d5d5363e640ee5340612123ea.zip
icmp: Discard echo replies too big to be forwarded to the guest
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>
-rw-r--r--icmp.c2
1 files changed, 2 insertions, 0 deletions
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;