From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Stuart Thomas <Stuart.Thomas@triageforge.co.uk>
Subject: [PATCH] icmp: Discard echo replies too big to be forwarded to the guest
Date: Mon, 23 Nov 2026 01:27:28 +0100 [thread overview]
Message-ID: <20261123002728.4072775-1-sbrivio@redhat.com> (raw)
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
reply other threads:[~2026-11-23 0:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123002728.4072775-1-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=Stuart.Thomas@triageforge.co.uk \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).