From nobody Tue Oct 29 18:53:36 2024 X-Original-To: dev-commits-src-all@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 4XdKCh63Nzz5bmy2; Tue, 29 Oct 2024 18:53:36 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XdKCh57bVz45Y5; Tue, 29 Oct 2024 18:53:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730228016; 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=c77f5SYgELE48BASr7vE7XA8hC/of+7hlJ360/URj8s=; b=MfgLKIqJBOaHrIhAOTVMkxXnQ6/bHQltTpD/Oq+gZ3goV3toegbOPEJlGakRG2mIhZjk3u tUJvA0+dAA4Q/I5vjcqD8+1fBjsdtCN77+H36bZc0H9agZOXw8odaDFx+l0Fw7XqwNSrrq m+lcJxzpb4kQS5jq007pLno+yvDvaYKBtj3wf85FvMN+50JohPO1tfInH/Rwubj/8uxZ2D hr5QArkzecA3w9asi+GNeqn1ppvrm45RQ1nCgy8ScpSViB4i5BRmoMqgSQhKyCfl1DM+Mh 6vqvFCOHOvV5LZhHqvNzmvvPK5wxjzLiskA5NHEyTg+QjdAWzy2zLiFPnvBDZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730228016; 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=c77f5SYgELE48BASr7vE7XA8hC/of+7hlJ360/URj8s=; b=T7BtEvvFIC0GWVGaQkAIDKv2U57xw4a7D/JlT2uFcXqvh32buarPQhYVGMkYkP+zFYPrMb YxuxwQ1R5JMzOHjka88nY+hMHt3Kod5Q/68mDKPgOcs3EP4RTD8s84cmeqmfZ/FGRuJZeR kjHUrZldN4vk974j/XWs+b3jOT57i4EMBxU1eTjHERe66tK4UZx3T9124622wkUuU1WwsS 8KwGV//OD/tmrxpH/7jtF36IOoErTaBkF2UKrkqte92R1KbKkdiJsmMnxRW8Qm/vt5j3Xn KLAMc9LLDeFaRiGFkJtoYZLMoHOQXVPgUJNFQsNKB8+SIPeO+FkWEddn2rhepA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730228016; a=rsa-sha256; cv=none; b=ciRWCUx/lezVZyCz4EhxyBSs7z+xOANgm7oHp9/KGAu5S45t8HNpSdawGb+I1Dyoiezp2Z LXIz6FFJ3xNj8csDQBi9qzvl4sR0L0EBohHEabgyA0u8H7iERJMmWProVnPPqn9qxdNxXY jbhX066HL8MGGv1meG4nkeTA10geCu0ml0wApPqBkvOw91gghxQCPTxnvJDeF/jyV0n4mC 9nyQaGemMvogj59phhn/Hs/b2ueqTw2zpg2B25Ny/Wb1qdRMlGxbyQdkD/WlZVti24xdXS JZJGVlJZW2414Pi7nOOiipRmFDctXW23B0kJJ9togDQE8MHI8DuKfZ0SZQzXoA== 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 4XdKCh4kkYzbYg; Tue, 29 Oct 2024 18:53:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49TIra7m035020; Tue, 29 Oct 2024 18:53:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TIraJ5035017; Tue, 29 Oct 2024 18:53:36 GMT (envelope-from git) Date: Tue, 29 Oct 2024 18:53:36 GMT Message-Id: <202410291853.49TIraJ5035017@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 50ca525bfe96 - releng/13.3 - bhyve/nvme: Fix out-of-bounds read in NVMe log page List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.3 X-Git-Reftype: branch X-Git-Commit: 50ca525bfe9633c887029b8aaeafc605a5414831 Auto-Submitted: auto-generated The branch releng/13.3 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=50ca525bfe9633c887029b8aaeafc605a5414831 commit 50ca525bfe9633c887029b8aaeafc605a5414831 Author: Chuck Tuffli AuthorDate: 2024-09-19 15:11:30 +0000 Commit: Ed Maste CommitDate: 2024-10-29 18:52:43 +0000 bhyve/nvme: Fix out-of-bounds read in NVMe log page The function nvme_opc_get_log_page in the file usr.sbin/bhyve/pci_nvme.c is vulnerable to buffer over-read. The value logoff is user controlled but never checked against the value of logsize. Thus the difference: logsize - logoff can underflow. Due to the sc structure layout, an attacker can dump internals fields of sc and the content of next heap allocation. Reported by: Synacktiv Reviewed by: emaste, jhb Security: HYP-07 Security: FreeBSD-SA-24:17.bhyve Approved by: so Sponsored by: The Alpha-Omega Project Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46021 (cherry picked from commit b0a24be007d83f7929de5b3fc320a29e6868067d) (cherry picked from commit a5be19efbb7c6b07d574ef048b2ebade00440873) (cherry picked from commit c8f75686adc6bc2078ade279d838cbc5b1745e71) --- usr.sbin/bhyve/pci_nvme.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index 3db306a19119..cbe4d87b6f60 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -1454,7 +1454,7 @@ nvme_opc_get_log_page(struct pci_nvme_softc* sc, struct nvme_command* command, logsize *= sizeof(uint32_t); logoff = ((uint64_t)(command->cdw13) << 32) | command->cdw12; - DPRINTF("%s log page %u len %u", __func__, logpage, logsize); + DPRINTF("%s log page %u offset %lu len %u", __func__, logpage, logoff, logsize); switch (logpage) { case NVME_LOG_ERROR: @@ -1466,7 +1466,7 @@ nvme_opc_get_log_page(struct pci_nvme_softc* sc, struct nvme_command* command, nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, command->prp1, command->prp2, (uint8_t *)&sc->err_log + logoff, - MIN(logsize - logoff, sizeof(sc->err_log)), + MIN(logsize, sizeof(sc->err_log) - logoff), NVME_COPY_TO_PRP); break; case NVME_LOG_HEALTH_INFORMATION: @@ -1489,7 +1489,7 @@ nvme_opc_get_log_page(struct pci_nvme_softc* sc, struct nvme_command* command, nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, command->prp1, command->prp2, (uint8_t *)&sc->health_log + logoff, - MIN(logsize - logoff, sizeof(sc->health_log)), + MIN(logsize, sizeof(sc->health_log) - logoff), NVME_COPY_TO_PRP); break; case NVME_LOG_FIRMWARE_SLOT: @@ -1501,7 +1501,7 @@ nvme_opc_get_log_page(struct pci_nvme_softc* sc, struct nvme_command* command, nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, command->prp1, command->prp2, (uint8_t *)&sc->fw_log + logoff, - MIN(logsize - logoff, sizeof(sc->fw_log)), + MIN(logsize, sizeof(sc->fw_log) - logoff), NVME_COPY_TO_PRP); break; case NVME_LOG_CHANGED_NAMESPACE: @@ -1513,7 +1513,7 @@ nvme_opc_get_log_page(struct pci_nvme_softc* sc, struct nvme_command* command, nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, command->prp1, command->prp2, (uint8_t *)&sc->ns_log + logoff, - MIN(logsize - logoff, sizeof(sc->ns_log)), + MIN(logsize, sizeof(sc->ns_log) - logoff), NVME_COPY_TO_PRP); memset(&sc->ns_log, 0, sizeof(sc->ns_log)); break;