From nobody Sun Oct 06 14:02:56 2024 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 4XM3rw3H9Dz5Y7JJ; Sun, 06 Oct 2024 14:02:56 +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 4XM3rw2cvdz424h; Sun, 6 Oct 2024 14:02:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728223376; 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=cTN8ONIZjJV/eT2VngR9PSAdWO+9pzJEDraFiDWRRb8=; b=AbwecJJ9Lx61AyO3S+8rMM3V177wBwjIZVJCXgXHNFlRbcdugN8+3oao73qICMEHHkl5Q3 4IO4Wtfhfq89pql7o6H1edKnu1N9N09GtywyVqeUvIZcYf1G76c+jbeUc62aQD0BcBO/Zm kQaL8yMm6yd9XTjN9ySz5u2wsOcvjqdlIA4hoAwUJ7SVZVJ/rw2t7Kxp9HAw9A19UAcHlM 0vXc2Ps3WjBnj2QZzys0+Lk57Ssn4+Q0hKprr1iD3WIJHcrCLjwoXOhd1lM68O4o5u+gOE hyvJmD7LBV4zOJu+pC/O0OZT3YV34ecc+2miktjw89YNf2gFaJNz6Jrfh5kMpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728223376; 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=cTN8ONIZjJV/eT2VngR9PSAdWO+9pzJEDraFiDWRRb8=; b=EX/myCTIqubHndntXGAwhTbkFaR0z3fczw4eW9KPO2gdRQmfGgUUdIA9cbPgIllH7BtSyY MZ+Z5iO+AeNX3gPFhVPsY2YrgrFSv0/gS86qfHYCKURQMOqBdPm6e2Uyf8hpha+4XR7MJ9 syS7ahzZzC0ftDPJf3KJ6lI1/P195nOWgZYn+Pe9BrVjPctskQ40edvgWYAm/LRLEU1Sd5 740xAgWLMu1lEutM1ObBIYrzoVrQC6FAbl8yv/o+9/mNuZozKeYHVaCg1DfSXDbpf9np02 v4pu0uv4rc1lz1jAMcSTmo6M7xvvxYMzxIm19K2EfxCyv8fSVc4O9grmSHMVLQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728223376; a=rsa-sha256; cv=none; b=DAUZtvuNmmsNniatfehfbAGZIZWZiXs4MqDreWpr0VjEOvmpT+LFOgNqJkX7sIVQf5fj8d h8OIkgy7ytEjALObls0RLOHxX5KRL9VXtjaOXIv30iLlxVEduWCkEdvOD2Z1mV6wRFYsFN 3bkjmB2elpUxS8AaX4OYXjuaMAAuZoqqQICV1heaH4SqhdykIiWkcU1NVtK0uQBE9IEsfA RvYnl6IRXSswnB1vDhvMZCGzfWlu2k3Bp/930Q02h7sNiYacguiES8IOLxFl+5CGdpdkOM 6Yh2Jy9XLTj8+de/uD+AVqt2ZJM1Xu5xBBqtvqZGo9UTNqzngvsI5PRTwJKMHg== 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 4XM3rw253Zz14HW; Sun, 6 Oct 2024 14:02:56 +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 496E2ucH046156; Sun, 6 Oct 2024 14:02:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 496E2uYg046153; Sun, 6 Oct 2024 14:02:56 GMT (envelope-from git) Date: Sun, 6 Oct 2024 14:02:56 GMT Message-Id: <202410061402.496E2uYg046153@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Chuck Tuffli Subject: git: b0a24be007d8 - main - bhyve/nvme: Fix out-of-bounds read in NVMe log page 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: chuck X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b0a24be007d83f7929de5b3fc320a29e6868067d Auto-Submitted: auto-generated The branch main has been updated by chuck: URL: https://cgit.FreeBSD.org/src/commit/?id=b0a24be007d83f7929de5b3fc320a29e6868067d commit b0a24be007d83f7929de5b3fc320a29e6868067d Author: Chuck Tuffli AuthorDate: 2024-09-19 15:11:30 +0000 Commit: Chuck Tuffli CommitDate: 2024-10-06 13:50:28 +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 --- 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;