opnsense-src/sys/dev/nvme
David Sloan 510404f2f4 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

(cherry picked from commit 7ea866eb14f8ec869a525442c03228b6701e1dab)
2023-10-08 20:41:25 -04:00
..
nvme.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
nvme_ahci.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_ctrlr.c nvme: Fix memory leak in pt ioctl commands 2023-10-08 20:41:25 -04:00
nvme_ctrlr_cmd.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_ns.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_ns_cmd.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_pci.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_private.h nvme: Fix locking protocol violation to fix suspend / resume 2023-09-28 15:05:15 -06:00
nvme_qpair.c nvme: Supress noise messages 2023-09-28 15:05:15 -06:00
nvme_sim.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_sysctl.c nvme: Add exclusion for ISR 2023-09-28 15:05:14 -06:00
nvme_test.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nvme_util.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00