aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2020-10-28 20:22:20 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2020-10-28 20:22:20 +0000
commitd9999ae9ca1d022bfac4d8834ce9a9e7929bbdae (patch)
treeca1897ee36f252cae79e3cd5d3d3f65b97dcd55d /sys
parent6dd1985bad7cfd0d89eb3b95b161ce3b01b4d844 (diff)
downloadsrc-d9999ae9ca1d022bfac4d8834ce9a9e7929bbdae.tar.gz
src-d9999ae9ca1d022bfac4d8834ce9a9e7929bbdae.zip
Fix use-after-free in icmp6_notify_error().
Reported by: Maxime Villard <max at m00nbsd.net> Reviewed by: markj MFC after: 3 days
Notes
Notes: svn path=/head/; revision=367114
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet6/icmp6.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c
index 51a20473ecd3..1a08dad7de64 100644
--- a/sys/netinet6/icmp6.c
+++ b/sys/netinet6/icmp6.c
@@ -917,6 +917,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
}
icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
eip6 = (struct ip6_hdr *)(icmp6 + 1);
+ bzero(&icmp6dst, sizeof(icmp6dst));
/* Detect the upper level protocol */
{
@@ -925,7 +926,6 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
int eoff = off + sizeof(struct icmp6_hdr) +
sizeof(struct ip6_hdr);
struct ip6ctlparam ip6cp;
- struct in6_addr *finaldst = NULL;
int icmp6type = icmp6->icmp6_type;
struct ip6_frag *fh;
struct ip6_rthdr *rth;
@@ -999,10 +999,11 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
}
rth0 = (struct ip6_rthdr0 *)
(mtod(m, caddr_t) + eoff);
+
/* just ignore a bogus header */
if ((rth0->ip6r0_len % 2) == 0 &&
(hops = rth0->ip6r0_len/2))
- finaldst = (struct in6_addr *)(rth0 + 1) + (hops - 1);
+ icmp6dst.sin6_addr = *((struct in6_addr *)(rth0 + 1) + (hops - 1));
}
eoff += rthlen;
nxt = rth->ip6r_nxt;
@@ -1056,13 +1057,10 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
*/
eip6 = (struct ip6_hdr *)(icmp6 + 1);
- bzero(&icmp6dst, sizeof(icmp6dst));
icmp6dst.sin6_len = sizeof(struct sockaddr_in6);
icmp6dst.sin6_family = AF_INET6;
- if (finaldst == NULL)
+ if (IN6_IS_ADDR_UNSPECIFIED(&icmp6dst.sin6_addr))
icmp6dst.sin6_addr = eip6->ip6_dst;
- else
- icmp6dst.sin6_addr = *finaldst;
if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL))
goto freeit;
bzero(&icmp6src, sizeof(icmp6src));
@@ -1074,13 +1072,11 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
icmp6src.sin6_flowinfo =
(eip6->ip6_flow & IPV6_FLOWLABEL_MASK);
- if (finaldst == NULL)
- finaldst = &eip6->ip6_dst;
ip6cp.ip6c_m = m;
ip6cp.ip6c_icmp6 = icmp6;
ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1);
ip6cp.ip6c_off = eoff;
- ip6cp.ip6c_finaldst = finaldst;
+ ip6cp.ip6c_finaldst = &icmp6dst.sin6_addr;
ip6cp.ip6c_src = &icmp6src;
ip6cp.ip6c_nxt = nxt;