[PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion
From: Andrew Stellman
Date: Wed Dec 02 2026 - 11:50:32 EST
From: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
nvme_set_temp_thresh() calls millicelsius_to_kelvin() before clamping
the value. From reading the code, an input close to LONG_MAX
overflows in that conversion, so the clamp then programs 0 K instead
of the maximum.
Clamp the millidegree input before converting it.
Fixes: 52deba0f02a9 ("nvme: hwmon: provide temperature min and max values for each sensor")
Signed-off-by: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
---
Tested on mainline 19cc08c1a6a6 (7.4.0-rc5) in arm64 QEMU with KASAN:
writing 9223372036854775807 to temp1_max set 0 K without the patch and
65535 K with it.
Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook) running Claude Opus
5.5; the fix was drafted with OpenAI GPT-6 (Codex).
A reproducer is available on request.
drivers/nvme/host/hwmon.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
index 406203d8b9ad..fd5aea5c5d9a 100644
--- a/drivers/nvme/host/hwmon.c
+++ b/drivers/nvme/host/hwmon.c
@@ -43,6 +43,8 @@ static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,
unsigned int threshold = sensor << NVME_TEMP_THRESH_SELECT_SHIFT;
int ret;
+ temp = clamp_val(temp, ABSOLUTE_ZERO_MILLICELSIUS,
+ kelvin_to_millicelsius(NVME_TEMP_THRESH_MASK));
temp = millicelsius_to_kelvin(temp);
threshold |= clamp_val(temp, 0, NVME_TEMP_THRESH_MASK);
--
2.53.0