Path: blob/main/website/static/security/patches/EN-12:02/ipv6refcount.patch
18096 views
Index: sys/netinet6/in6.c1===================================================================2--- sys/netinet6/in6.c.orig3+++ sys/netinet6/in6.c4@@ -1369,6 +1369,8 @@ in6_purgeaddr(struct ifaddr *ifa)5}67cleanup:8+ if (ifa0 != NULL)9+ ifa_free(ifa0);1011plen = in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); /* XXX */12if ((ia->ia_flags & IFA_ROUTE) && plen == 128) {13@@ -1393,8 +1395,6 @@ cleanup:14return;15ia->ia_flags &= ~IFA_ROUTE;16}17- if (ifa0 != NULL)18- ifa_free(ifa0);1920in6_unlink_ifa(ia, ifp);21}22@@ -1667,14 +1667,19 @@ in6_lifaddr_ioctl(struct socket *so, u_long cmd, c23hostid = IFA_IN6(ifa);2425/* prefixlen must be <= 64. */26- if (64 < iflr->prefixlen)27+ if (64 < iflr->prefixlen) {28+ if (ifa != NULL)29+ ifa_free(ifa);30return EINVAL;31+ }32prefixlen = iflr->prefixlen;3334/* hostid part must be zero. */35sin6 = (struct sockaddr_in6 *)&iflr->addr;36if (sin6->sin6_addr.s6_addr32[2] != 0 ||37sin6->sin6_addr.s6_addr32[3] != 0) {38+ if (ifa != NULL)39+ ifa_free(ifa);40return EINVAL;41}42} else43@@ -2265,14 +2265,20 @@ in6_ifawithifp(struct ifnet *ifp, struct in6_addr44IN6_IFADDR_RUNLOCK();45return (struct in6_ifaddr *)ifa;46}47- IN6_IFADDR_RUNLOCK();4849/* use the last-resort values, that are, deprecated addresses */50- if (dep[0])51+ if (dep[0]) {52+ ifa_ref((struct ifaddr *)dep[0]);53+ IN6_IFADDR_RUNLOCK();54return dep[0];55- if (dep[1])56+ }57+ if (dep[1]) {58+ ifa_ref((struct ifaddr *)dep[1]);59+ IN6_IFADDR_RUNLOCK();60return dep[1];61+ }6263+ IN6_IFADDR_RUNLOCK();64return NULL;65}6667Index: sys/netinet6/ip6_input.c68===================================================================69--- sys/netinet6/ip6_input.c.orig70+++ sys/netinet6/ip6_input.c71@@ -879,19 +879,23 @@ passin:72* as our interface address (e.g. multicast addresses, addresses73* within FAITH prefixes and such).74*/75- if (deliverifp && !ip6_getdstifaddr(m)) {76+ if (deliverifp) {77struct in6_ifaddr *ia6;7879- ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);80- if (ia6) {81- if (!ip6_setdstifaddr(m, ia6)) {82- /*83- * XXX maybe we should drop the packet here,84- * as we could not provide enough information85- * to the upper layers.86- */87+ if ((ia6 = ip6_getdstifaddr(m)) != NULL) {88+ ifa_free(&ia6->ia_ifa);89+ } else {90+ ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);91+ if (ia6) {92+ if (!ip6_setdstifaddr(m, ia6)) {93+ /*94+ * XXX maybe we should drop the packet here,95+ * as we could not provide enough information96+ * to the upper layers.97+ */98+ }99+ ifa_free(&ia6->ia_ifa);100}101- ifa_free(&ia6->ia_ifa);102}103}104105Index: sys/netinet/tcp_input.c106===================================================================107--- sys/netinet/tcp_input.c.orig108+++ sys/netinet/tcp_input.c109@@ -512,6 +512,8 @@ tcp6_input(struct mbuf **mp, int *offp, int proto)110(caddr_t)&ip6->ip6_dst - (caddr_t)ip6);111return IPPROTO_DONE;112}113+ if (ia6)114+ ifa_free(&ia6->ia_ifa);115116tcp_input(m, *offp);117return IPPROTO_DONE;118@@ -1240,7 +1242,8 @@ relocked:119rstreason = BANDLIM_RST_OPENPORT;120goto dropwithreset;121}122- ifa_free(&ia6->ia_ifa);123+ if (ia6)124+ ifa_free(&ia6->ia_ifa);125}126#endif /* INET6 */127/*128129130