[PATCH v2 1/2] nvme: zns: reject an out-of-range zone append size limit
From: shao.mingyin
Date: Sun Nov 22 2026 - 09:48:40 EST
From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
nvme_set_max_append() derives a sector limit by shifting 1 by ZASL + 3.
ZASL is a byte from the Identify Controller ZNS data. Values of 29 or
larger require a shift of at least 32 bits, which is undefined for the
32-bit operand. ZASL = 28 shifts into bit 31, which a signed operand
cannot express either.
Use an unsigned shift for representable values. If the reported limit
exceeds the range of max_zone_append, use max_hw_sectors, the same
limit used when ZASL is zero. The hardware transfer limit is smaller
than any append limit that requires a shift of at least 32 bits.
Fixes: 240e6ee272c0 ("nvme: support for zoned namespaces")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Changes in v2:
- Drop the warning for values the driver cannot represent (Christoph).
- Clarify that such a value can be valid and why the fallback is safe.
v1: https://lore.kernel.org/r/20261115012752774qFGtgUXwZKwN-2LDj0D80@xxxxxxxxxx
drivers/nvme/host/zns.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index e31ec6f4f94fbe872d346516b02dd1e6a2223872..a93f3b152faaad34199e0d6276536be0c0ae8767 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -27,8 +27,8 @@ static int nvme_set_max_append(struct nvme_ctrl *ctrl)
return status;
}
- if (id->zasl)
- ctrl->max_zone_append = 1 << (id->zasl + 3);
+ if (id->zasl && id->zasl + 3 < 32)
+ ctrl->max_zone_append = 1U << (id->zasl + 3);
else
ctrl->max_zone_append = ctrl->max_hw_sectors;
kfree(id);
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
--
2.43.0