Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet: zero the reservation report tail beyond NUMD
@ 2026-11-25  6:14 Guixin Liu
  2026-11-25  6:27 ` sashiko-bot
  2026-11-25  7:04 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Guixin Liu @ 2026-11-25  6:14 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Nilay Shroff, Daniel Wagner, Hannes Reinecke
  Cc: linux-nvme

The reservation report handler allocates a buffer of 4 * (NUMD + 1)
bytes and copies it to the command SGL, but the data is sent back to
the host using the SGL length, which is independent of NUMD. When the
host supplies a buffer larger than NUMD, the tail beyond the copied
data is returned uninitialised, leaking kernel heap contents to a
fabric host.

Zero the SGL tail beyond the transferred data, as the discovery log
page handler already does.

Fixes: 5a47c2080a73 ("nvmet: support reservation feature")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Found by code inspection, reproduced and verified on a QEMU loopback
nvmet-tcp target (7.3.0, KASAN, init_on_alloc=0) with a null_blk
namespace and reservations enabled.

Reproduction: issue a Reservation Report passthru with NUMD=15 (64
bytes) and a 64 KiB host buffer, after a 64 KiB write to dirty the
page allocator. On the unpatched target the returned tail beyond the
64-byte data structure contains stale kernel heap data (kernel
pointers and strings, 30/30 runs). With this patch the same recipe
returns an all-zero tail (15/15 runs).

Regression: register/acquire/report flows return correct data; a
NUMD below the extended structure size still fails with Invalid
Field, and EDS=0 with a 128-bit host identifier still fails with
Host Identifier Inconsistent Format.

Note: with init_on_alloc=1 the page allocator zeroes the SGL pages
and the leak is not observable; the reproduction above disables it.

 drivers/nvme/target/pr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
index 8c818f24815b..63ea607d4864 100644
--- a/drivers/nvme/target/pr.c
+++ b/drivers/nvme/target/pr.c
@@ -900,6 +900,9 @@ static void nvmet_execute_pr_report(struct nvmet_req *req)
 
 	put_unaligned_le16(num_ctrls, data->regctl);
 	status = nvmet_copy_to_sgl(req, 0, data, num_bytes);
+	if (!status && req->transfer_len > num_bytes)
+		status = nvmet_zero_sgl(req, num_bytes,
+					req->transfer_len - num_bytes);
 	kfree(data);
 out:
 	nvmet_req_complete(req, status);
-- 
2.43.7



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvmet: zero the reservation report tail beyond NUMD
  2026-11-25  6:14 [PATCH] nvmet: zero the reservation report tail beyond NUMD Guixin Liu
@ 2026-11-25  6:27 ` sashiko-bot
  2026-11-25  7:14   ` Guixin Liu
  2026-11-25  7:04 ` Christoph Hellwig
  1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-11-25  6:27 UTC (permalink / raw)
  To: Guixin Liu; +Cc: linux-nvme

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] nvmet: torn read of rkey in nvmet_pr_update_reg_rkey() [1]
--

commit 58bea4d71647eb54c1d0685be4714b3cb40c9a6f
Author: Guixin Liu <kanie@linux.alibaba.com>

nvmet: zero the reservation report tail beyond NUMD

This commit zeroes any remaining bytes in the command SGL beyond the
requested reservation report size in nvmet_execute_pr_report() so that
uninitialized kernel memory is not returned to the host.

> diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
> index 8c818f24815bd..63ea607d48646 100644
> --- a/drivers/nvme/target/pr.c
> +++ b/drivers/nvme/target/pr.c
> @@ -900,6 +900,9 @@ static void nvmet_execute_pr_report(struct nvmet_req *req)
>  
>  	put_unaligned_le16(num_ctrls, data->regctl);
>  	status = nvmet_copy_to_sgl(req, 0, data, num_bytes);
> +	if (!status && req->transfer_len > num_bytes)
> +		status = nvmet_zero_sgl(req, num_bytes,
> +					req->transfer_len - num_bytes);
>  	kfree(data);
>  out:
>  	nvmet_req_complete(req, status);

[Severity: Critical]
This problem wasn't introduced by this patch, but can RCU readers such as
nvmet_execute_pr_report() observe a torn 64-bit reg->rkey [1] on
32-bit architectures?

When the target registrant is not the current reservation holder,
nvmet_pr_update_reg_attr() updates the live entry in pr->registrant_list
in place via nvmet_pr_update_reg_rkey():

drivers/nvme/target/pr.c:nvmet_pr_update_reg_rkey() {
	reg->rkey = *(u64 *)attr;
}

drivers/nvme/target/pr.c:nvmet_pr_update_reg_attr() {
	...
	if (reg != holder) {
		change_attr(reg, attr);
		return NVME_SC_SUCCESS;
	}
	...
}

On 32-bit systems, the 64-bit store to reg->rkey splits into two 32-bit
stores, so a concurrent RCU reader can observe half of the old key and
half of the new key, corrupting the reported key or causing reservation
validation failures.

[1] https://sashiko.dev/#/bug/linux-b537252d-fab1-48b2-bcc6-de089d7cd907

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125061453.230238-1-kanie@linux.alibaba.com?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvmet: zero the reservation report tail beyond NUMD
  2026-11-25  6:14 [PATCH] nvmet: zero the reservation report tail beyond NUMD Guixin Liu
  2026-11-25  6:27 ` sashiko-bot
@ 2026-11-25  7:04 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-11-25  7:04 UTC (permalink / raw)
  To: Guixin Liu
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Nilay Shroff, Daniel Wagner, Hannes Reinecke, linux-nvme

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvmet: zero the reservation report tail beyond NUMD
  2026-11-25  6:27 ` sashiko-bot
@ 2026-11-25  7:14   ` Guixin Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Guixin Liu @ 2026-11-25  7:14 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: linux-nvme



在 2026/11/25 14:27, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 1 related pre-existing issue it does not
> introduce:
> - [Critical] nvmet: torn read of rkey in nvmet_pr_update_reg_rkey() [1]
> --
>
> commit 58bea4d71647eb54c1d0685be4714b3cb40c9a6f
> Author: Guixin Liu <kanie@linux.alibaba.com>
>
> nvmet: zero the reservation report tail beyond NUMD
>
> This commit zeroes any remaining bytes in the command SGL beyond the
> requested reservation report size in nvmet_execute_pr_report() so that
> uninitialized kernel memory is not returned to the host.
>
>> diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
>> index 8c818f24815bd..63ea607d48646 100644
>> --- a/drivers/nvme/target/pr.c
>> +++ b/drivers/nvme/target/pr.c
>> @@ -900,6 +900,9 @@ static void nvmet_execute_pr_report(struct nvmet_req *req)
>>  
>>  	put_unaligned_le16(num_ctrls, data->regctl);
>>  	status = nvmet_copy_to_sgl(req, 0, data, num_bytes);
>> +	if (!status && req->transfer_len > num_bytes)
>> +		status = nvmet_zero_sgl(req, num_bytes,
>> +					req->transfer_len - num_bytes);
>>  	kfree(data);
>>  out:
>>  	nvmet_req_complete(req, status);
> [Severity: Critical]
> This problem wasn't introduced by this patch, but can RCU readers such as
> nvmet_execute_pr_report() observe a torn 64-bit reg->rkey [1] on
> 32-bit architectures?
>
> When the target registrant is not the current reservation holder,
> nvmet_pr_update_reg_attr() updates the live entry in pr->registrant_list
> in place via nvmet_pr_update_reg_rkey():
>
> drivers/nvme/target/pr.c:nvmet_pr_update_reg_rkey() {
> 	reg->rkey = *(u64 *)attr;
> }
>
> drivers/nvme/target/pr.c:nvmet_pr_update_reg_attr() {
> 	...
> 	if (reg != holder) {
> 		change_attr(reg, attr);
> 		return NVME_SC_SUCCESS;
> 	}
> 	...
> }
>
> On 32-bit systems, the 64-bit store to reg->rkey splits into two 32-bit
> stores, so a concurrent RCU reader can observe half of the old key and
> half of the new key, corrupting the reported key or causing reservation
> validation failures.
>
> [1] https://sashiko.dev/#/bug/linux-b537252d-fab1-48b2-bcc6-de089d7cd907
What Sashiko report is another issue, not the bug this patch introduced.

I will take a look to see if we should fix.

Best Regards,
Guixin Liu
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25  7:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  6:14 [PATCH] nvmet: zero the reservation report tail beyond NUMD Guixin Liu
2026-11-25  6:27 ` sashiko-bot
2026-11-25  7:14   ` Guixin Liu
2026-11-25  7:04 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox