From nobody Mon Oct 02 16:05:47 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 4Rzm5R4TmGz4wDLl; Mon, 2 Oct 2023 16:05: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 4Rzm5R3fbxz4JxD; Mon, 2 Oct 2023 16:05:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696262747; 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=PT6uWIaYLYHilwiKWaqUYLIOpOyrO0r8z2qWrdS7zso=; b=FP3zsVarw1bs43DYHerSjTMbscljvXG05bvMKx3TnbwnWrPzc/r7hgW/9s8d1rKb6NdP8S 1B0LWYsG9moK3yBwTzQ4jjXLIpji92wEfLa61oEJEpVexPMuleotp2hMvoBYbXp0vyeceu y2AHszn4USByc0ilhy5ROZE0qKz4GrRNTYc/at+jeOnIeYBTYWAnizUN1qvUn6uG7M3A9v vTGPjF+2zSstt3/R+1+gzAbCnU219Fl7U9F/IzO2YhK2PjU5zt+G6ml+5hr1hkWK61mCPK TapXTgEDFJ7aQxaE/StbBoN3RuxMvpBLIDioqt+C8dIwMjuv5LQ/unPKfu9mOQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696262747; a=rsa-sha256; cv=none; b=gJ4GNTHASYw+Dv8YI9rknBc4OShiufye1pACsiqY5TR7ajPxMeifdmpIK1HRYZ97XCCgPc 50F06qg5PJBIAvFNBd81aZqe8YcP60M/KICfG4DoqRbtE0ENZ5o3B46Z2buamxOM+uY/CV sewr2ctDruV2LBN0Q1zPuid3nX4Wri/DhHIlcHjYQ1M021GLdLtGCarWOZPclL6nPQyK9A ODqODD38RD5/8kFSPGJZSJfeIJ30gGV1eIiGvj8EyqCdXSwD6DxxpGmw/53lskBWZKTeWV VT5YC/eI8NtJ7UFxcJKnCxXuASE8XYi2nXKEE8WRu96Lzws04uPsOb9E3qSWdQ== 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=1696262747; 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=PT6uWIaYLYHilwiKWaqUYLIOpOyrO0r8z2qWrdS7zso=; b=SYpg2yA7hRoMz8aEG7C7n99wkI8Ne34S16VEvjXZmj7DM/uvo3Z6BA3a6iSqbE7GemV7Tj bsCGbzlCxuHAlyfNfGjngaPFhKwCMXOwj52UvtPVLjMX1v4PESNACZuztt0m4rx8l4DSPu D9YMz7dx4NHUmrkCHo2oSNwk5NmWARxlkhnNhQyH+DeRInqWLU9sMe94UNQ7AF2gpp04AW ez3r4qrAGLe1E0qc/Ci3H0rxfhDu3y7hKst5onM12qnrv+6wqBp/kI6mEuwXFjrbVXwTUq oly/jvjv796qeqGS319ko2p9mndMMe4wT9gu3ubN2qkI0pA1xHSHnCQvpHnNWw== 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 4Rzm5R2jbkz3wY; Mon, 2 Oct 2023 16:05:47 +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 392G5lYv053063; Mon, 2 Oct 2023 16:05:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 392G5lmI053060; Mon, 2 Oct 2023 16:05:47 GMT (envelope-from git) Date: Mon, 2 Oct 2023 16:05:47 GMT Message-Id: <202310021605.392G5lmI053060@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 7ea866eb14f8 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 7ea866eb14f8ec869a525442c03228b6701e1dab Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7ea866eb14f8ec869a525442c03228b6701e1dab commit 7ea866eb14f8ec869a525442c03228b6701e1dab Author: David Sloan AuthorDate: 2023-09-07 16:22:21 +0000 Commit: Mark Johnston CommitDate: 2023-10-02 15:50:14 +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 --- 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); }