From owner-svn-src-all@freebsd.org Sat Oct 17 20:33:10 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7B0A4441C11; Sat, 17 Oct 2020 20:33:10 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CDF8Q2d5Nz4b6S; Sat, 17 Oct 2020 20:33:10 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3D633276AC; Sat, 17 Oct 2020 20:33:10 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09HKXAEF003234; Sat, 17 Oct 2020 20:33:10 GMT (envelope-from melifaro@FreeBSD.org) Received: (from melifaro@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09HKXAjG003233; Sat, 17 Oct 2020 20:33:10 GMT (envelope-from melifaro@FreeBSD.org) Message-Id: <202010172033.09HKXAjG003233@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: melifaro set sender to melifaro@FreeBSD.org using -f From: "Alexander V. Chernikov" Date: Sat, 17 Oct 2020 20:33:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366795 - head/sys/netinet X-SVN-Group: head X-SVN-Commit-Author: melifaro X-SVN-Commit-Paths: head/sys/netinet X-SVN-Commit-Revision: 366795 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Oct 2020 20:33:10 -0000 Author: melifaro Date: Sat Oct 17 20:33:09 2020 New Revision: 366795 URL: https://svnweb.freebsd.org/changeset/base/366795 Log: Fix sleepq_add panic happening with too wide net epoch in mcast control. PR: 250413 Reported by: Christopher Hall Reviewed by: ae Differential Revision: https://reviews.freebsd.org/D26827 Modified: head/sys/netinet/in_mcast.c Modified: head/sys/netinet/in_mcast.c ============================================================================== --- head/sys/netinet/in_mcast.c Sat Oct 17 17:31:06 2020 (r366794) +++ head/sys/netinet/in_mcast.c Sat Oct 17 20:33:09 2020 (r366795) @@ -1905,7 +1905,7 @@ inp_getmoptions(struct inpcb *inp, struct sockopt *sop * this in order to allow groups to be joined when the routing * table has not yet been populated during boot. * - * Returns NULL if no ifp could be found. + * Returns NULL if no ifp could be found, otherwise return referenced ifp. * * FUTURE: Implement IPv4 source-address selection. */ @@ -1926,13 +1926,16 @@ inp_lookup_mcast_ifp(const struct inpcb *inp, if (!in_nullhost(ina)) { IN_IFADDR_RLOCK(&in_ifa_tracker); INADDR_TO_IFP(ina, ifp); + if (ifp != NULL) + if_ref(ifp); IN_IFADDR_RUNLOCK(&in_ifa_tracker); } else { - fibnum = inp ? inp->inp_inc.inc_fibnum : 0; - nh = fib4_lookup(fibnum, gsin->sin_addr, 0, 0, 0); - if (nh != NULL) + fibnum = inp ? inp->inp_inc.inc_fibnum : RT_DEFAULT_FIB; + nh = fib4_lookup(fibnum, gsin->sin_addr, 0, NHR_NONE, 0); + if (nh != NULL) { ifp = nh->nh_ifp; - else { + if_ref(ifp); + } else { struct in_ifaddr *ia; struct ifnet *mifp; @@ -1943,6 +1946,7 @@ inp_lookup_mcast_ifp(const struct inpcb *inp, if (!(mifp->if_flags & IFF_LOOPBACK) && (mifp->if_flags & IFF_MULTICAST)) { ifp = mifp; + if_ref(ifp); break; } } @@ -1966,6 +1970,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt struct ip_moptions *imo; struct in_multi *inm; struct in_msource *lims; + struct epoch_tracker et; int error, is_new; ifp = NULL; @@ -1997,9 +2002,10 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt if (!IN_MULTICAST(ntohl(gsa->sin.sin_addr.s_addr))) return (EINVAL); + NET_EPOCH_ENTER(et); if (sopt->sopt_valsize == sizeof(struct ip_mreqn) && mreqn.imr_ifindex != 0) - ifp = ifnet_byindex(mreqn.imr_ifindex); + ifp = ifnet_byindex_ref(mreqn.imr_ifindex); else ifp = inp_lookup_mcast_ifp(inp, &gsa->sin, mreqn.imr_address); @@ -2023,6 +2029,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt ssa->sin.sin_addr = mreqs.imr_sourceaddr; + NET_EPOCH_ENTER(et); ifp = inp_lookup_mcast_ifp(inp, &gsa->sin, mreqs.imr_interface); CTR3(KTR_IGMPV3, "%s: imr_interface = 0x%08x, ifp = %p", @@ -2065,7 +2072,8 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt if (gsr.gsr_interface == 0 || V_if_index < gsr.gsr_interface) return (EADDRNOTAVAIL); - ifp = ifnet_byindex(gsr.gsr_interface); + NET_EPOCH_ENTER(et); + ifp = ifnet_byindex_ref(gsr.gsr_interface); break; default: @@ -2074,9 +2082,13 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt return (EOPNOTSUPP); break; } + NET_EPOCH_EXIT(et); - if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) + if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) { + if (ifp != NULL) + if_rele(ifp); return (EADDRNOTAVAIL); + } IN_MULTI_LOCK(); @@ -2265,6 +2277,7 @@ out_inp_unlocked: } ip_mfilter_free(imf); } + if_rele(ifp); return (error); } @@ -2740,7 +2753,6 @@ inp_setmoptions(struct inpcb *inp, struct sockopt *sop { struct ip_moptions *imo; int error; - struct epoch_tracker et; error = 0; @@ -2847,9 +2859,7 @@ inp_setmoptions(struct inpcb *inp, struct sockopt *sop case IP_ADD_SOURCE_MEMBERSHIP: case MCAST_JOIN_GROUP: case MCAST_JOIN_SOURCE_GROUP: - NET_EPOCH_ENTER(et); error = inp_join_group(inp, sopt); - NET_EPOCH_EXIT(et); break; case IP_DROP_MEMBERSHIP: