]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
nvme: Fix memory leak in pt ioctl commands
authorDavid Sloan <david.sloan@eideticom.com>
Thu, 7 Sep 2023 16:22:21 +0000 (10:22 -0600)
committerMark Johnston <markj@FreeBSD.org>
Mon, 2 Oct 2023 15:50:14 +0000 (11:50 -0400)
commit7ea866eb14f8ec869a525442c03228b6701e1dab
tree095ff080a46d3079b376de32832e0fa7996a6adf
parentf156cd892b55c04a39fa06d1899e6e316de77f03
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 <david.sloan@eideticom.com>
PR: 273626
Reviewed by: imp, markj
MFC after: 1 week
sys/dev/nvme/nvme_ctrlr.c