From nobody Fri Oct 11 15:42:11 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 4XQ9q72gZJz5Z37s; Fri, 11 Oct 2024 15:42:11 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XQ9q727P5z4tnt; Fri, 11 Oct 2024 15:42:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728661331; 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=J7FTP5ma12LccVMVT1orpL9L0W0vXUPd7THbnLH69zw=; b=X3nXy4XCjzy2HeWEvlBRbsiU3shprPU3OZdS2v2CPvn2izxWGqPRs8d3NjV9ffbVsnGtOZ JhQ3yiJSu2bhYcKCRYh/5J1l5ELanJsMiX9wMGaWkdjACblcWX7Ogc2J9LDG7NWDYQxupM k0na0ao4jTPsg8jjHumRW9RrTzsW0PiQGO4qXwjFBvAf17wSDcUbd9bfRHeUXoU1GuRdck e3lqxFWRrJCvPr3AQDT6UGQImYjv0jIEyIl8oqiBCtjupbaqeculW1YdwhLSuEPAXb4+uc eZ5kwzF86DuLTCElzoQHUsGzMPmk1Xe+lfSUznuQbRlBtsdZB+Px6QAAr5AmNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728661331; 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=J7FTP5ma12LccVMVT1orpL9L0W0vXUPd7THbnLH69zw=; b=CkKkJ41riRWnMgy4ezoBYtt16BZ/OWX6icXaxyTeh++ALXoPL9BAcEwAcOd2gfZrWRXJyY yK4PuSFo0ET4RodL/FYfxvmRBMv1eiBeTaIOcli9jx6eKT0LeFF+i6vPyaKWhVcOVeJj4U u7gL2E5RycXI2Lvm8e3Wx2U54lcaZHrcfxmTOt1E0XLtAdNPTFzm1MObD6HQybdowDL0J/ daR83/gLSzbEsv2FwWsRX5kPERozm9YFg7xQiV5txHom34z0qCftqUOU1U+6gCoEYY51Oj LNqfzuY/fyaP2pwIqEqqZpagJxgJHsNLYBbSF+SqSje55BQqBM9XOeiTpbCymg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728661331; a=rsa-sha256; cv=none; b=EA6p+9JKpQrxGbVYBYKh33O17IruXaEmRKQAe1+VxnBESSfCNZGoG+lfWsDx1LGEXuzbGQ 2vNBRpvRzOg1Q5dEyX/bWYq85q8hQyf7vEFZ5Tz29gBVufwYNsvm++YGa8Xwa0GeFZ/E9B ET45oqJNHbY0OmNI4qp0GhPJTcFnL0YIDNqf41Vgq0o64U2+vThjklc5CEpfpl2RzDPFYH 9pLwfvXis28XX7x9mBdm/qYP2MQyXwKDlfIQwI8UOhkvoGZUjxI1YXRhKklEY2dKkl6DqJ r/teNpJzAkdQOT6Qrdqw0pEJL7MvS5bA/e2VhMDQbqIJrzwa2JcXBULfJJmIyw== 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 4XQ9q71kp4zng8; Fri, 11 Oct 2024 15:42:11 +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 49BFgBek067788; Fri, 11 Oct 2024 15:42:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49BFgBC4067785; Fri, 11 Oct 2024 15:42:11 GMT (envelope-from git) Date: Fri, 11 Oct 2024 15:42:11 GMT Message-Id: <202410111542.49BFgBC4067785@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: a5be19efbb7c - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: a5be19efbb7c6b07d574ef048b2ebade00440873 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=a5be19efbb7c6b07d574ef048b2ebade00440873 commit a5be19efbb7c6b07d574ef048b2ebade00440873 Author: Chuck Tuffli AuthorDate: 2024-09-19 15:11:30 +0000 Commit: Ed Maste CommitDate: 2024-10-11 15:34:27 +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 Sponsored by: Alpha-Omega Project, The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46021 (cherry picked from commit b0a24be007d83f7929de5b3fc320a29e6868067d) --- 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 45ab1b11fda4..b8eb24d91b49 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -1398,7 +1398,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: @@ -1410,7 +1410,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: @@ -1433,7 +1433,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: @@ -1445,7 +1445,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: @@ -1457,7 +1457,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;