From c7ede54cbd2e2b25385325600958ba0124e31cc0 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Fri, 3 Jul 2020 14:51:16 +0200 Subject: Drop bogus IPv6 messages Drop IPv6 message shorter than what's mentioned in the payload length header (+ the size of the IPv6 header). They're invalid an could lead to data leakage in icmp6_send_echoreply(). --- src/ip6_input.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ip6_input.c b/src/ip6_input.c index dfcbfd6..d88d1ab 100644 --- a/src/ip6_input.c +++ b/src/ip6_input.c @@ -49,6 +49,13 @@ void ip6_input(struct mbuf *m) goto bad; } + // Check if the message size is big enough to hold what's + // set in the payload length header. If not this is an invalid + // packet + if (m->m_len < ntohs(ip6->ip_pl) + sizeof(struct ip6)) { + goto bad; + } + /* check ip_ttl for a correct ICMP reply */ if (ip6->ip_hl == 0) { icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS); -- cgit v1.1 From f1941d6da6cade08f47153224304183df66b6199 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Fri, 3 Jul 2020 14:56:27 +0200 Subject: Fix MTU check The size for Header has to be accounted for as well. --- src/ip6_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ip6_input.c b/src/ip6_input.c index d88d1ab..a83e4f8 100644 --- a/src/ip6_input.c +++ b/src/ip6_input.c @@ -44,7 +44,7 @@ void ip6_input(struct mbuf *m) goto bad; } - if (ntohs(ip6->ip_pl) > slirp->if_mtu) { + if (ntohs(ip6->ip_pl) + sizeof(struct ip6) > slirp->if_mtu) { icmp6_send_error(m, ICMP6_TOOBIG, 0); goto bad; } -- cgit v1.1