From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 68DAE5A026E; Mon, 23 Nov 2026 01:27:28 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] icmp: Discard echo replies too big to be forwarded to the guest Date: Mon, 23 Nov 2026 01:27:28 +0100 Message-ID: <20261123002728.4072775-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: QI2B7GES6MRKXBA4JEUGLJTWJEUFMUHR X-Message-ID-Hash: QI2B7GES6MRKXBA4JEUGLJTWJEUFMUHR X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Stuart Thomas X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Stuart Thomas 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 Signed-off-by: Stuart Thomas Fixes: 1d807fc720bd ("passt: Introduce ICMP echo proxy") [sbrivio: commit message] Signed-off-by: Stefano Brivio --- 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