From 21f42492acf855db36664741063bb5959b9fecc5 Mon Sep 17 00:00:00 2001 From: gallatin Date: Thu, 10 May 2018 16:19:41 +0000 Subject: [PATCH] Fix a panic in the IPv6 multicast code. Use LIST_FOREACH_SAFE in in6m_disconnect() since we're deleting and freeing item from the membership list while traversing the list. Reviewed by: mmacy Sponsored by: Netflix --- sys/netinet6/in6_mcast.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/netinet6/in6_mcast.c b/sys/netinet6/in6_mcast.c index fa8093cd5c3c..6213b8fd0f99 100644 --- a/sys/netinet6/in6_mcast.c +++ b/sys/netinet6/in6_mcast.c @@ -581,7 +581,7 @@ in6m_disconnect(struct in6_multi *inm) struct ifnet *ifp; struct ifaddr *ifa; struct in6_ifaddr *ifa6; - struct in6_multi_mship *imm; + struct in6_multi_mship *imm, *imm_tmp; struct ifmultiaddr *ifma, *ll_ifma; ifp = inm->in6m_ifp; @@ -607,7 +607,8 @@ in6m_disconnect(struct in6_multi *inm) if (ifa->ifa_addr->sa_family != AF_INET6) continue; ifa6 = (void *)ifa; - LIST_FOREACH(imm, &ifa6->ia6_memberships, i6mm_chain) { + LIST_FOREACH_SAFE(imm, &ifa6->ia6_memberships, + i6mm_chain, imm_tmp) { if (inm == imm->i6mm_maddr) { LIST_REMOVE(imm, i6mm_chain); free(imm, M_IP6MADDR);