From nobody Sat Nov 19 17:48:47 2022 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 4NF1Nb4qNRz4hSmx; Sat, 19 Nov 2022 17:48:47 +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 4NF1Nb4CZpz44KV; Sat, 19 Nov 2022 17:48:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668880127; 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=OCDiyoK7Hmjw+XpOp5dPUKjnyRgR1u0XLurDaiIW1O4=; b=J7hHtG3UwmKH1EAGaUVfrPikKjHPGTnG+tqoZRbMz+QYqNB0QwHsvQ+PUsEfzg2SUAQPdZ EK2yWokeT9UwDmr3vWBKDcvFVw9sHoE6oPLqgbdBWmNJGA4TVlLNfb1VXB6iSB0iAbNjBe SycTCuf4sVEn7wJF8bxBFHcDg05XcAqulr78BRVUQPe6uAWHFWUknH8Oih8eKQ3kAjIEUc SsaZVJYJ1xy9F2dFuTI5sf0uO8hsE8oW5BWZ8kMNsu9zpJakN3R0hlvYN2VKogSqDKvcEX y4QaZg6VKgpKOfQARfZcbUZAXVqlzo29qo68IT7f9Jn17LsU4Y9ga2wZ6yEBMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668880127; 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=OCDiyoK7Hmjw+XpOp5dPUKjnyRgR1u0XLurDaiIW1O4=; b=CIGvVs5ZxSktt8QoHAiQLBaNRM1XV5gG1/L8Li69Ylfj8nNz2+AJObynGaHGRQvFbBAUfM aVlFGUxoDuliL32WBT222GKnom86UZKkgQKP28Dcqp3eqNopXkD+wXjQHWLgGhVRSpAvoH i7fMpHayg1SlurEjUthLdIDW25yJqVPfMgHSdHLUCzF7/YFExPXiC3do91VlL5lMwxOqj2 dt5vKyZWCyKq66Boot1/7/xuclmGmYY7QfatkjyVUDdOpxcj/WyXysAJRwzhfQp7/usdiP IWr0q+wVPy002R4JGlNQ1NM+I6PTo+gpS8rByKvLiJSnXhKn+EOIS4/bB7jvSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668880127; a=rsa-sha256; cv=none; b=eqF4XzGEdZN49Ly6hVAYm/PX+PQlLleZ+WpAzARw41pbLVkRdWprd9L2Oiy9pSVG3sz4tq 9TbXf1I8kYSFfr3S4b22wKDJqYnlz0L/lXAqMcksuUyXXkO2u+K5SYaNcGKzuHj8c3STuz dzirbIqLJmqmYZLzxloNeQnixPVcXQmYrttKOyLLtT+vcbTdfGUknIEFVN/7w5MrmMTQHD 8Bj5wxXvs50IhDrXSlbcG0knw/5xJiNI/MPbcpde8pvO/yMb6a64o2yilg959p2EKzwizY un+TEi5LeNziSogP448R6qm+IXhZU3p7S0fJ8BthCJGFP31Bf4xk6Lpm2p3zVQ== 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 4NF1Nb2vClztlS; Sat, 19 Nov 2022 17:48:47 +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 2AJHml3a024850; Sat, 19 Nov 2022 17:48:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AJHmlTP024849; Sat, 19 Nov 2022 17:48:47 GMT (envelope-from git) Date: Sat, 19 Nov 2022 17:48:47 GMT Message-Id: <202211191748.2AJHmlTP024849@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Chuck Tuffli Subject: git: a00b97054a50 - stable/13 - bhyve nvme: Fix out-of-bound IOV array access 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: a00b97054a504792eb6fa028728726f5c37744c3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by chuck: URL: https://cgit.FreeBSD.org/src/commit/?id=a00b97054a504792eb6fa028728726f5c37744c3 commit a00b97054a504792eb6fa028728726f5c37744c3 Author: Chuck Tuffli AuthorDate: 2022-06-09 18:19:32 +0000 Commit: Chuck Tuffli CommitDate: 2022-11-20 01:48:45 +0000 bhyve nvme: Fix out-of-bound IOV array access Summary: NVMe operations indicate the memory region(s) associated with a command via physical region pages (PRPs). Since each PRP has a fixed size, contiguous memory regions larger than the PRP size require multiple PRP entries. Instead of issuing a blockif call for each PRP, the NVMe emulation concatenates multiple contiguous PRP entries into a single blockif request. The test for contiguous regions has a bug such that it mistakenly treats an initial PRP address of zero as a contiguous range and concatenates it with the previous. But because there is no previous IOV, the concatenation code corrupts the IO request structure and leads to a segmentation fault when the blockif request completes. Fix is to test for the existence of a previous range before trying to concatenate the current range with the previous one. While in the area, rename pci_nvme_append_iov_req()'s lba parameter to offset to match its usage. PR: 264177 (cherry picked from commit 88951aaaee73b87121b0f121224fe188a5b5e6e3) --- usr.sbin/bhyve/pci_nvme.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c index bc7b82bda619..1b2ad6177f40 100644 --- a/usr.sbin/bhyve/pci_nvme.c +++ b/usr.sbin/bhyve/pci_nvme.c @@ -2176,9 +2176,10 @@ pci_nvme_out_of_range(struct pci_nvme_blockstore *nvstore, uint64_t slba, static int pci_nvme_append_iov_req(struct pci_nvme_softc *sc, struct pci_nvme_ioreq *req, - uint64_t gpaddr, size_t size, int do_write, uint64_t lba) + uint64_t gpaddr, size_t size, int do_write, uint64_t offset) { int iovidx; + bool range_is_contiguous; if (req == NULL) return (-1); @@ -2187,8 +2188,17 @@ pci_nvme_append_iov_req(struct pci_nvme_softc *sc, struct pci_nvme_ioreq *req, return (-1); } - /* concatenate contig block-iovs to minimize number of iovs */ - if ((req->prev_gpaddr + req->prev_size) == gpaddr) { + /* + * Minimize the number of IOVs by concatenating contiguous address + * ranges. If the IOV count is zero, there is no previous range to + * concatenate. + */ + if (req->io_req.br_iovcnt == 0) + range_is_contiguous = false; + else + range_is_contiguous = (req->prev_gpaddr + req->prev_size) == gpaddr; + + if (range_is_contiguous) { iovidx = req->io_req.br_iovcnt - 1; req->io_req.br_iov[iovidx].iov_base = @@ -2202,7 +2212,7 @@ pci_nvme_append_iov_req(struct pci_nvme_softc *sc, struct pci_nvme_ioreq *req, } else { iovidx = req->io_req.br_iovcnt; if (iovidx == 0) { - req->io_req.br_offset = lba; + req->io_req.br_offset = offset; req->io_req.br_resid = 0; req->io_req.br_param = req; }