From nobody Fri Jan 20 20:25:32 2023 X-Original-To: dev-commits-src-main@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 4Nz9wr5P81z30tQ3; Fri, 20 Jan 2023 20:25:32 +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 4Nz9wr4sSjz3LGk; Fri, 20 Jan 2023 20:25:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674246332; 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=gyGMabOUuJ4Hw7d/yY45Uk/rDHuAW5bcQmXA8X1kdTA=; b=XMdazZhqOcbQH2Ar7zJkw3uG0+C4prGWgM2XWNRqHqkBEt/VBEM47WEJMqVueAUJbyuRzL zxlD8eq+0xC3VNVeYGdKBKjgYt1GosM8O8CJz+j1qaC4BVuxShwCDIGTbdG6eaUhDxfmV9 liXIWKWtFKIgovBBk/oB/SCHxU1VDdsqOcAnrgyB7WXrD51f/R6jwPMOEPSAl6XvZQBxcB /PNhocM0W4b0+ov5PkorakClroJFa/tR3QNwZ9aSlnikBO3igX2MpG9pQ6XPSHwgFXb/z/ eRH03inSv1K0Fzugh6k2WPJA0ARtjhpsWvU0MoCergiTr8REM6On2+NRPnDufA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674246332; 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=gyGMabOUuJ4Hw7d/yY45Uk/rDHuAW5bcQmXA8X1kdTA=; b=V0if0gttV3s0MRXXAV0p3DP/yvx8dBBz3NYQAznneslWZjf72q3kDfZVKS/ZatPbF7Z/iG KpE3WTqQeAbHOdBvV277QrUlnDLtAU/CgSeOYc4hj2LkYqY8twh9R5gTred3afSGYFs9Vy ZwoAbrwVQhMbz6zeITMzZCvkCfchpuRmYah4XpTONF+3SJWviQUYqHF1+ZcGwK1xkLjuRx 1I286e2oKFuboP90Es8ZCkEqcNJM4GUrNI9CaM3R2CzEp+BGqJ7n7+uCTv9QGMUQK4PpRU UpQWOY9hHVChnx1Gj6irh/FliaAjDIpM4V05sZTaLGZ1IuMQNGw5ElqTsY3JCg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674246332; a=rsa-sha256; cv=none; b=Vh5JhwsHUYUN9fc7i1IoOSYgSJB6UyH3GL8/E4mYZ44MUSEY70/sCZvAo2MoJ1sBAAFxbm CzX2h3ujTxQWL755pXY8GKMtcln73xAKx3WVPrHu2xc+GGllM+8d09SNwRTxJMczlxemg3 pNVXy9zclb1ppNRL5+fwCxyihUo1Mn5rCqYaeVAhCJjhnEp49k1ZmecFgbPXSM89aljv0q xD2bcPEHdsRRj5C8yhCPAHZ61dIysgt2nDYEft87CZugrZUWd0kydXUwDmo5kUDpFlCdQt C9QuHXGL5xQz4lugzpwqfBu/qicRWczsWbamga4q5USYSKgwdYR/dhQc3LUTXQ== 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 4Nz9wr3wCmzkMf; Fri, 20 Jan 2023 20:25:32 +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 30KKPW06000565; Fri, 20 Jan 2023 20:25:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30KKPWfv000564; Fri, 20 Jan 2023 20:25:32 GMT (envelope-from git) Date: Fri, 20 Jan 2023 20:25:32 GMT Message-Id: <202301202025.30KKPWfv000564@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Wing Subject: git: 27029bc08f1d - main - vmm: fix use after free in ppt_detach() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 27029bc08f1d7fdb39b2aee6ff8263f68dd93495 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=27029bc08f1d7fdb39b2aee6ff8263f68dd93495 commit 27029bc08f1d7fdb39b2aee6ff8263f68dd93495 Author: Robert Wing AuthorDate: 2023-01-20 11:25:27 +0000 Commit: Robert Wing CommitDate: 2023-01-20 11:25:27 +0000 vmm: fix use after free in ppt_detach() The vmm module destroys the host_domain before unloading the ppt module causing a use after free. This can happen when kldunload'ing vmm. Reviewed by: markj, jhb Differential Revision: https://reviews.freebsd.org/D38072 --- sys/amd64/vmm/intel/vtd.c | 2 ++ sys/amd64/vmm/io/iommu.c | 1 + sys/amd64/vmm/io/ppt.c | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/amd64/vmm/intel/vtd.c b/sys/amd64/vmm/intel/vtd.c index 8f06dc823364..21e81223f6ee 100644 --- a/sys/amd64/vmm/intel/vtd.c +++ b/sys/amd64/vmm/intel/vtd.c @@ -446,6 +446,8 @@ vtd_add_device(void *arg, uint16_t rid) struct vtdmap *vtdmap; uint8_t bus; + KASSERT(dom != NULL, ("domain is NULL")); + bus = PCI_RID2BUS(rid); ctxp = ctx_tables[bus]; pt_paddr = vtophys(dom->ptp); diff --git a/sys/amd64/vmm/io/iommu.c b/sys/amd64/vmm/io/iommu.c index 6a589f153815..01ce29539ec2 100644 --- a/sys/amd64/vmm/io/iommu.c +++ b/sys/amd64/vmm/io/iommu.c @@ -258,6 +258,7 @@ iommu_cleanup(void) } IOMMU_DISABLE(); IOMMU_DESTROY_DOMAIN(host_domain); + host_domain = NULL; IOMMU_CLEANUP(); } diff --git a/sys/amd64/vmm/io/ppt.c b/sys/amd64/vmm/io/ppt.c index edb65a3ac07b..26dad1832b10 100644 --- a/sys/amd64/vmm/io/ppt.c +++ b/sys/amd64/vmm/io/ppt.c @@ -182,7 +182,9 @@ ppt_detach(device_t dev) num_pptdevs--; TAILQ_REMOVE(&pptdev_list, ppt, next); pci_disable_busmaster(dev); - iommu_add_device(iommu_host_domain(), pci_get_rid(dev)); + + if (iommu_host_domain() != NULL) + iommu_add_device(iommu_host_domain(), pci_get_rid(dev)); return (0); }