nvme-ioctl: fix leaked requests on mapping error
PATCH 1/1 nvme-ioctl: fix leaked requests on mapping error
From: Keith Busch <[email protected]>
All the callers assume nvme_map_user_request() frees the request on a failure. This wasn't happening on invalid metadata or io_uring command flags, so we've been leaking those requests.
Fixes 23fd22e55b767b ("nvme: wire up fixed buffer support for nvme passthrough")
Fixes 7c2fd76048e95d ("nvme: fix metadata handling in nvme-passthrough")
Signed-off-by Keith Busch <[email protected]>
---
Without this patch, here's a nasty trick to lock up a queue's hctx:
for i in $(seq 1 5000); do nvme read /dev/nvme0n1 --data-size=4096 --metadata-size=16; done
drivers/nvme/host/ioctl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/nvme/host/ioctl.c +8 -4
@@ -128,8 +128,10 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,if (!nvme_ctrl_sgl_supported (ctrl))dev_warn_once (ctrl->device,"using unchecked data buffer\n" );if (has_metadata) { -if (!supports_metadata) -return -EINVAL ; +if (!supports_metadata) { + ret = -EINVAL ; + goto out; + }if (!nvme_ctrl_meta_sgl_supported (ctrl))dev_warn_once (ctrl->device,"using unchecked metadata buffer\n" );
@@ -139,8 +141,10 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,struct iov_iter iter;/* fixedbufs is only for non-vectored io */ -if (WARN_ON_ONCE (flags &NVME_IOCTL_VEC )) -return -EINVAL ; +if (WARN_ON_ONCE (flags &NVME_IOCTL_VEC )) { + ret = -EINVAL ; + goto out; + } ret =io_uring_cmd_import_fixed (ubuffer, bufflen,rq_data_dir (req), &iter, ioucmd);if (ret <0 )
Signature · 1 line
2.43.5
Quoted 9 lines · Keith Busch
From: Keith Busch <[email protected]>
All the callers assume
nvme_map_user_request()frees the request on a failure. This wasn't happening on invalid metadata orio_uringcommand flags, so we've been leaking those requests.Fixes 23fd22e55b767b ("nvme: wire up fixed buffer support for nvme passthrough")Fixes 7c2fd76048e95d ("nvme: fix metadata handling in nvme-passthrough")Signed-off-by Keith Busch <[email protected]>
Looks good to me.
Reviewed-by Damien Le Moal <[email protected]>
Signature · 2 lines
Damien Le Moal Western Digital Research
Reviewed-by Kanchan Joshi <[email protected]>
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>