[PATCH 5/5] nvme: bound the reservation report retry loop
shao.mingyin at zte.com.cn
shao.mingyin at zte.com.cn
Sat Nov 14 09:27:58 PST 2026
From: Shao Mingyin <shao.mingyin at zte.com.cn>
nvme_pr_read_reservation() first reads the reservation status header to
learn the number of registrants, allocates a buffer of that size, and
then reads the full status. If the registrant count changed in between,
it frees the buffer and jumps back to get_num_regs. There is no limit on
the number of retries:
if (num_regs != get_unaligned_le16(&rse->regctl)) {
kfree(rse);
goto get_num_regs;
}
The count comes from the controller and a target that keeps flipping it
(possible for a malicious NVMe-oF target) makes the ioctl loop forever.
Each iteration issues two Reservation Report commands and allocates up
to struct_size(..., 65535) bytes, and the calling process ends up in an
uninterruptible loop that cannot be killed. Daemons that issue this
ioctl, such as cluster lock managers, get stuck with it.
Allow the retry only a few times and report -EAGAIN when the controller
still does not provide a consistent report.
Fixes: 28c97ba38ff9 ("nvme: Add pr_ops read_reservation support")
Cc: stable at vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin at zte.com.cn>
---
Tested on 7.3.0-next-20261030 (QEMU/TCG guest) with the loop transport and
a TEST-ONLY nvmet hook that alternates the registrant count between the
header-only and the full Reservation Report. The hook is compiled into
both kernels and only the host fix differs; no extra hardware is needed.
One PR key is registered, then the guest issues
IOC_PR_READ_RESERVATION. The header report always says one registrant
and the full report says two, so the retry loop never converges:
unpatched patched
ioctl never returns (the runner ioctl returns -EAGAIN after
hits its timeout) three inconsistent report attempts
drivers/nvme/host/pr.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c
index fe7dbe264815..fab3bad2e2e0 100644
--- a/drivers/nvme/host/pr.c
+++ b/drivers/nvme/host/pr.c
@@ -275,7 +275,7 @@ static int nvme_pr_read_reservation(struct block_device *bdev,
struct pr_held_reservation *resv)
{
struct nvme_reservation_status_ext tmp_rse, *rse;
- int ret, i, num_regs;
+ int ret, i, num_regs, retries = 0;
u32 rse_len;
bool eds;
@@ -305,6 +305,8 @@ static int nvme_pr_read_reservation(struct block_device *bdev,
if (num_regs != get_unaligned_le16(&rse->regctl)) {
kfree(rse);
+ if (++retries >= 3)
+ return -EAGAIN;
goto get_num_regs;
}
--
2.43.0
More information about the Linux-nvme
mailing list