Re: [PATCH 2/5] nvme: map passthrough data when the length is nonzero
From: Caleb Sander Mateos
Date: Fri Nov 20 2026 - 13:04:06 EST
On Sat, Nov 14, 2026 at 11:13 AM <shao.mingyin@xxxxxxxxxx> wrote:
>
> From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
>
> nvme_submit_user_cmd() skips mapping when the user address is zero,
> even if a nonzero data length was supplied. Passthrough ioctls and
> NVME_IOCTL_SUBMIT_IO can therefore submit a data-transfer command
> without a mapped payload. For example, the loop target returns a
> Data SGL Length Invalid status instead of rejecting the user buffer.
>
> Map whenever a length is given and let the mapping helper validate the
> address. This also permits address zero if the process has valid
> memory mapped there, matching the io_uring passthrough behavior from
> commit 99fde895ff56 ("nvme: map uring_cmd data even if address is 0").
>
> Fixes: d29ec8241c10 ("nvme: submit internal commands through the block layer")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
> ---
> Tested on 7.3.0-next-20261030 (QEMU/TCG guest) with the loop transport
> and a file-backed namespace.
>
> NVME_IOCTL_IO_CMD with addr=0 and a nonzero data_len skips the mapping
> on the unpatched kernel and submits the command with an empty data
> pointer, so the target rejects it with "Data SGL Length Invalid" (status
> 0x600f). With the patch the mapping helper rejects the null user
> address with -EFAULT before the command is submitted:
>
> unpatched patched
> control read (valid addr) ret 0 control read (valid addr) ret 0
> read addr=0 len=4096 ret 0x600f read addr=0 len=4096 -EFAULT
> write addr=0 len=4096 ret 0x600f write addr=0 len=4096 -EFAULT
>
> drivers/nvme/host/ioctl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
> index a87c9ca9d06c..22efc5412416 100644
> --- a/drivers/nvme/host/ioctl.c
> +++ b/drivers/nvme/host/ioctl.c
> @@ -207,7 +207,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
> return PTR_ERR(req);
>
> req->timeout = timeout;
> - if (ubuffer && bufflen) {
> + if (bufflen) {
This is a potential UAPI change if a userspace process was setting
only the addr field 0 in struct nvme_user_io/nvme_passthru_cmd to opt
out of data mapping. (This seems quite possible if a struct
nvme_passthru_cmd is reused for multiple commands, one with data and
one without. Or if userspace isn't bothering to initialize data_len
when it sets addr = 0.) I agree I would have used this condition if I
were designing this UAPI from scratch, but I'm concerned about
breaking existing users. Are there real applications mapping data at
virtual address 0? The change for nvme_uring_cmd was needed to work
with kernel io_uring registered buffers, where addr = 0 represents
"from the start of the registered buffer".
Best,
Caleb
> ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer,
> meta_len, NULL, flags);
> if (ret)
> --
> 2.43.0
>