From: Guixin Liu <kanie@linux.alibaba.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Nilay Shroff <nilay@linux.ibm.com>,
Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH] nvmet: zero the reservation report tail beyond NUMD
Date: Wed, 25 Nov 2026 14:14:52 +0800 [thread overview]
Message-ID: <20261125061453.230238-1-kanie@linux.alibaba.com> (raw)
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
next reply other threads:[~2026-11-25 6:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 6:14 Guixin Liu [this message]
2026-11-25 6:27 ` [PATCH] nvmet: zero the reservation report tail beyond NUMD sashiko-bot
2026-11-25 7:14 ` Guixin Liu
2026-11-25 7:04 ` Christoph Hellwig
2026-11-25 9:51 ` Nilay Shroff
2026-11-30 15:56 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125061453.230238-1-kanie@linux.alibaba.com \
--to=kanie@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=dwagner@suse.de \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=nilay@linux.ibm.com \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.