From nobody Mon Oct 09 00:58:53 2023 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 4S3gdn5hntz4wTd5; Mon, 9 Oct 2023 00:58:53 +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 4S3gdn5CqRz3KqV; Mon, 9 Oct 2023 00:58:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696813133; 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=URldmZNMM8i4lze01/OKzGLTygz3A4oeF/hWmxFEJlQ=; b=Hjjnxvt4n/EUcPaBNi+Kvj4hpDPfLfXz1glxpVxvPZidL9ioAYJ41swiiTUePv1YOp6E+J zv4aEOJURQ16Rr7gv96RDeE7kgBu3gDuOpAX4lnZZheWAmm+qq15e+g2vja81D2LI+zPaa z/VF/Q28asFcq89necKH+LO2n/mFvDFT+NwSZnIWL9n2RjwLd23wHuB9rFHBObEwJRmJXt riu7+iAb8JFihoz9R+3YQZVAbUXO/2qEcamMKXu3gvDPBGGIiymYNoypdgobS7gkN522Vw CnXz1Ec4VcrFi1nRbaVTeGkM6WHRLiwF3hi6It8Z2GViEGKWC5K7EJ3IAbZDdg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696813133; a=rsa-sha256; cv=none; b=Q2lJRp6t6rjB4w6WIhdfRqRaiPqjVNRBZmuawEK2HswpAbQBmU9XjRYPi+Z9dHmNlSnlTf SeMMds1+Y19bf6BcwFUZpmUShRInI8SShb7I7wu38m1AuCfsrd7FSqgwdILLbn4gxHi2OH ZyZKoCL/NILKbt9DQeiBQIJG19B+mve8MWhqSzvrbzdjIvgagOwn9sjAOxLsIl9q7LE2kk 3eOIBqWHL3fZqRm34eDMpXxAZsgRrHuWuJRrBPkuO2N7x7r368DBcRToqmrYfqhKDXnAsj dd+SAlQUzu4N5ZUC/RxFxBGqkSVMEuZ6o20xYCRmtSoW8j52M467wEH7YObnYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696813133; 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=URldmZNMM8i4lze01/OKzGLTygz3A4oeF/hWmxFEJlQ=; b=uKMcLjWaoUHLwp6mBfbgVJ8ABZLz7Hl5DhKEOiC7EF+OBt2IlR8000UrhKU/mnLZtPpO5w 31IQIwLIdsGzDPegoRsfe9a+LcdAxvIweEAp7JPS2EIp160Pn5mu5fk3n4cFQHG5GWN75v KCXtwAoph/+y4/owUEqZhAtfrHol6Aaw3UseDvPyadbxx81QQ+y4TPFelt1RWpAqFo7riR BvPWSSwbNLk78q2iI8wZq68usjWnC3A38gllLS4B1gVUXiODcK8MhLMwKQeW/n0aqvjh9p FhGUhnOlQP59FaDQGNguZTN69HNN6LkC/tfz+DVuARRBOxqQH8kkXFB5IGVJ/w== 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 4S3gdn4GQ3zbZX; Mon, 9 Oct 2023 00:58:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3990wrRs040165; Mon, 9 Oct 2023 00:58:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3990wrWl040162; Mon, 9 Oct 2023 00:58:53 GMT (envelope-from git) Date: Mon, 9 Oct 2023 00:58:53 GMT Message-Id: <202310090058.3990wrWl040162@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 510404f2f49e - stable/14 - nvme: Fix memory leak in pt ioctl commands 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 510404f2f49e0797bbef0034b3c13831bed78b35 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=510404f2f49e0797bbef0034b3c13831bed78b35 commit 510404f2f49e0797bbef0034b3c13831bed78b35 Author: David Sloan AuthorDate: 2023-09-07 16:22:21 +0000 Commit: Mark Johnston CommitDate: 2023-10-09 00:41:25 +0000 nvme: Fix memory leak in pt ioctl commands When running nvme passthrough commands through the ioctl interface memory is mapped with vmapbuf() but not unmapped. This results in leaked memory whenever a process executes an nvme passthrough command with a data buffer. This can be replicated with a simple c function (error checks skipped for brevity): void leak_memory(int nvme_ns_fd, uint16_t nblocks) { struct nvme_pt_command pt = { .cmd = { .opc = NVME_OPC_READ, .cdw12 = nblocks - 1, }, .len = nblocks * 512, // Assumes devices with 512 byte lba .is_read = 1, // Reads and writes should both trigger leak } void *buf; posix_memalign(&buf, nblocks * 512); pt.buf = buf; ioctl(nvme_ns_fd, NVME_PASSTHROUGH_COMMAND, &pt); free(buf); } Signed-off-by: David Sloan PR: 273626 Reviewed by: imp, markj MFC after: 1 week (cherry picked from commit 7ea866eb14f8ec869a525442c03228b6701e1dab) --- sys/dev/nvme/nvme_ctrlr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 30a5ee81b2a4..ef4d7daa6efa 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -1334,8 +1334,9 @@ nvme_ctrlr_passthrough_cmd(struct nvme_controller *ctrlr, mtx_sleep(pt, mtx, PRIBIO, "nvme_pt", 0); mtx_unlock(mtx); -err: if (buf != NULL) { + vunmapbuf(buf); +err: uma_zfree(pbuf_zone, buf); PRELE(curproc); }