From nobody Mon Oct 09 18:13:23 2023 X-Original-To: dev-commits-src-branches@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 4S46bS0gv5z4w12x; Mon, 9 Oct 2023 18:13:24 +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 4S46bS0D99z4M1c; Mon, 9 Oct 2023 18:13:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696875204; 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=8n9gHZ0M6oMzTykDoqzzJqukssaLPe3ZEsczhmrQMQE=; b=aI1a1omGrPRvtIZqTsEUWy98BC5b0LGnZAl1GvOI1Oj4DIWfug90JuIUqX4GbdJmZbdPMd QnEttBw8MmcR0OXBwakRozEBN//W4Va0ExqVwpVi+HcaZ6zi54kMc4fWO2CLWw6Hz3kyj4 arMWAvBwCvtPkH0wqswbdUQ9N5fixLxk2WIEpPOejU7vmrJo3q3ZiQBMOzLDISo1BEAyHF 0qYZS++fE7iHuMoMrvgbgtJ5D8Oc/wAHLJ6USWFGO6gOWmaFoMWDXXLjqwRSjf6T8D+ZjE dRH6nLToIu2qjqy6wgTFrYvU0hdkp23MaYSAZNRqafbjAkJoLJeBX3oxcWkaiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696875204; a=rsa-sha256; cv=none; b=NnrylfBK8OozD8ocHF4I9195RLm09aIC7mVsL01wZxXLTXFDYpxzmgi63ArFlV7usrON64 PB33xLzT/LRg4/4nV/vgBFIMiD6WlR5b9PwdIIGX5iZL8oPuTFc1d3oq5Z4FdYkFFNqM50 uHNmJGqRGuxP4b45rH4I6bdpX2yHrCNzeQxoHEZczmNF8auA1pUZOBoZApVgqmC/BDhZ/0 JE4QSgw6zqFsVDz/mE5x06ZA7yJsxoaPcNzKBsp5uEtmtXoDHypqe/EIyBSAvc3zpHcH3I QxNIXmly6SGIv5/q0lvmPAtRR2zvVV/C6/2du6k93rabk6gWIj3VSpuhzJmyCQ== 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=1696875204; 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=8n9gHZ0M6oMzTykDoqzzJqukssaLPe3ZEsczhmrQMQE=; b=vtEXaQHv5Sz0vt5ql+WqQnGnwKL7IePR00pznTSpxljAVlnumeD5yeMwdpYrYu44+nycQA 5ZIdCQfc08dpbgC2oQBdfM7NVGkgpsLMGhJhkeSFUzJ/K3b+NGmC+y5+7KNU+a/LDv0lYu ccIz/vJdK2ZZ9sz2U7q5yzxx9cB9J8k4jKmbOl5nbvu0p81DgihgL2xv6hxj3EsbsN8EA2 bCC0enY6eyCDrH2lwDNNOyG2JNhBE2Rjy22P6aGnUgJtA1rSZQ8sOK4KchhL/qPszX5vSk egXDwyesjeeyURlJWnlEhHj2xCisO8Mn8vpRuitKTeC8xferOoNkJRdN2Pmb4A== 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 4S46bR6PFTz15lZ; Mon, 9 Oct 2023 18:13:23 +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 399IDNT8072279; Mon, 9 Oct 2023 18:13:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 399IDNvh072276; Mon, 9 Oct 2023 18:13:23 GMT (envelope-from git) Date: Mon, 9 Oct 2023 18:13:23 GMT Message-Id: <202310091813.399IDNvh072276@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: 11ab396fc995 - releng/14.0 - nvme: Fix memory leak in pt ioctl commands List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 11ab396fc995b72d9d5f5d54d0bc93840a7fbf76 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=11ab396fc995b72d9d5f5d54d0bc93840a7fbf76 commit 11ab396fc995b72d9d5f5d54d0bc93840a7fbf76 Author: David Sloan AuthorDate: 2023-09-07 16:22:21 +0000 Commit: Mark Johnston CommitDate: 2023-10-09 18:05:36 +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 Approved by: re (gjb) PR: 273626 Reviewed by: imp, markj MFC after: 1 week (cherry picked from commit 7ea866eb14f8ec869a525442c03228b6701e1dab) (cherry picked from commit 510404f2f49e0797bbef0034b3c13831bed78b35) --- 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); }