From nobody Thu Apr 28 00:34:52 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E237C1AB71C8; Thu, 28 Apr 2022 00:34:52 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kpc8D62H6z4ksH; Thu, 28 Apr 2022 00:34:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651106092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Cbr+G/iWSTDnfthGatqSUzRJkGNuwI14VHqoW/QLRRw=; b=A/n5hdAdcAnI1FGhhnIXcyUZdlFtF7bnXzQ2/9tcAza2/W0EpGfXLinLRW8t5EUMxJ2thR COak2JrAebgfAONXQlmBPaliiwU4DLsmlUqu11gNptiqWVQJaBdhNmheQLFYJV6gRSVVx9 85eNRuGfWenRUJwHd1RkInmzd4eIRlzVASB8GAsSkBs4LkTqtUcWElIZ67de/GDOv7JLlN YOk+Hn2NVPdlft+xUkozQUagEuDu++cVED+ax1Mo2KnfMJC6YWZ8godaGJYc6CRQdxrn7L 1qPCzkg75bubRClmgW69pQ1U7MyFrvIyfdxfkksTfTexWulUPJEygv89fUNiOw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AF7156628; Thu, 28 Apr 2022 00:34:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23S0YqjO066366; Thu, 28 Apr 2022 00:34:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23S0YqHx066365; Thu, 28 Apr 2022 00:34:52 GMT (envelope-from git) Date: Thu, 28 Apr 2022 00:34:52 GMT Message-Id: <202204280034.23S0YqHx066365@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 46242829baa3 - stable/13 - mld6: Ensure that mld_domifattach() always succeeds List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 46242829baa3c822b8e7376a71f1d0fa2be1c5c5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651106092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Cbr+G/iWSTDnfthGatqSUzRJkGNuwI14VHqoW/QLRRw=; b=VbaFvP2LNjdYwgNZIvFad1zm9VqUpI5Nuu83sg9icKJRqtO/LlU2di2ZU4osU/k5IjBfgJ Vukj/SbzSgF8l+NoRL7dZNbNCQ+mHM03U9YFZSrzjnoIBJ5YvxIOyGyFivoQOxoScKPw0L ufAZXpfPyHq5qFIz4Es33KYXt4iyxzZfbCjjvDfmcXjODjmvekIyzR1wFKMFbuRS5vIIkP MzBSF8HE7EW0WooN1HvFAg6jvAQzeVIjouY9MxEIii0cnKquafIYpMP9eGcShSqCSXtJRG qH7zx/C0J4JCu6e/n/uYhfuDyHO6MaWsuN6eBTsMmkC4igQfc64dOuG8BoBB6w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651106092; a=rsa-sha256; cv=none; b=fl+MbvpL7V7IjBbtPgawDRCm5MRnQf+zSMaDQxGpask97EqPSwfZohBjvM41W0TmuCrBJt AhDIjzGEeYVXVs6pKGkoUecawRzdPhJKaT1O1pE88pFfh5qIk4mRp8CPbfVjAPqQo5CxPe fPm2/Ii8+fmK2V12dcJHcoJXH5RuynsfsIS/KSfQdLSF0n6AWaRiqbKOmfQilbHPIkW81S W4f2nw2rcxB/pU9FO4detmU8SU7l5/8pNJgST6VfOk+7VMczQE/NQVP6UyyKBesgpRQXet ODNV0J9rq5njMfb7bmIVoVGInNTQdNT5s7p5CjsnvNr4qH78gTL9c9GkrwvvFQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=46242829baa3c822b8e7376a71f1d0fa2be1c5c5 commit 46242829baa3c822b8e7376a71f1d0fa2be1c5c5 Author: Mark Johnston AuthorDate: 2022-04-21 17:22:09 +0000 Commit: Mark Johnston CommitDate: 2022-04-28 00:34:17 +0000 mld6: Ensure that mld_domifattach() always succeeds mld_domifattach() does a memory allocation under the global MLD mutex and so can fail, but no error handling prevents a null pointer dereference in this case. The mutex is only needed when updating the global softc list; the allocation and static initialization of the softc does not require this mutex. So, reduce the scope of the mutex and use M_WAITOK for the allocation. PR: 261457 Sponsored by: The FreeBSD Foundation (cherry picked from commit 5d691ab4f03d436d38f46777c3c117cf5a27f1bc) --- sys/netinet6/mld6.c | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/sys/netinet6/mld6.c b/sys/netinet6/mld6.c index c4948158bba8..1c984db70e93 100644 --- a/sys/netinet6/mld6.c +++ b/sys/netinet6/mld6.c @@ -104,8 +104,6 @@ __FBSDID("$FreeBSD$"); #define KTR_MLD KTR_INET6 #endif -static struct mld_ifsoftc * - mli_alloc_locked(struct ifnet *); static void mli_delete_locked(const struct ifnet *); static void mld_dispatch_packet(struct mbuf *); static void mld_dispatch_queue(struct mbufq *, int); @@ -470,45 +468,17 @@ mld_is_addr_reported(const struct in6_addr *addr) } /* - * Attach MLD when PF_INET6 is attached to an interface. - * - * SMPng: Normally called with IF_AFDATA_LOCK held. + * Attach MLD when PF_INET6 is attached to an interface. Assumes that the + * current VNET is set by the caller. */ struct mld_ifsoftc * mld_domifattach(struct ifnet *ifp) { struct mld_ifsoftc *mli; - CTR3(KTR_MLD, "%s: called for ifp %p(%s)", - __func__, ifp, if_name(ifp)); - - MLD_LOCK(); - - mli = mli_alloc_locked(ifp); - if (!(ifp->if_flags & IFF_MULTICAST)) - mli->mli_flags |= MLIF_SILENT; - if (mld_use_allow) - mli->mli_flags |= MLIF_USEALLOW; - - MLD_UNLOCK(); - - return (mli); -} - -/* - * VIMAGE: assume curvnet set by caller. - */ -static struct mld_ifsoftc * -mli_alloc_locked(/*const*/ struct ifnet *ifp) -{ - struct mld_ifsoftc *mli; - - MLD_LOCK_ASSERT(); - - mli = malloc(sizeof(struct mld_ifsoftc), M_MLD, M_NOWAIT|M_ZERO); - if (mli == NULL) - goto out; + CTR3(KTR_MLD, "%s: called for ifp %p(%s)", __func__, ifp, if_name(ifp)); + mli = malloc(sizeof(struct mld_ifsoftc), M_MLD, M_WAITOK | M_ZERO); mli->mli_ifp = ifp; mli->mli_version = MLD_VERSION_2; mli->mli_flags = 0; @@ -517,13 +487,15 @@ mli_alloc_locked(/*const*/ struct ifnet *ifp) mli->mli_qri = MLD_QRI_INIT; mli->mli_uri = MLD_URI_INIT; mbufq_init(&mli->mli_gq, MLD_MAX_RESPONSE_PACKETS); + if ((ifp->if_flags & IFF_MULTICAST) == 0) + mli->mli_flags |= MLIF_SILENT; + if (mld_use_allow) + mli->mli_flags |= MLIF_USEALLOW; + MLD_LOCK(); LIST_INSERT_HEAD(&V_mli_head, mli, mli_link); + MLD_UNLOCK(); - CTR2(KTR_MLD, "allocate mld_ifsoftc for ifp %p(%s)", - ifp, if_name(ifp)); - -out: return (mli); }