mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Stellman <bugs@stellman-greene.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>, Sagi Grimberg <sagi@grimberg.me>,
	Akinobu Mita <akinobu.mita@gmail.com>,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] nvme-hwmon: clamp threshold input before Kelvin conversion
Date: Wed,  2 Dec 2026 11:49:56 -0500	[thread overview]
Message-ID: <20261202164956.49925-1-bugs@stellman-greene.com> (raw)

From: Andrew Stellman <astellman@stellman-greene.com>

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@stellman-greene.com>
---
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


                 reply	other threads:[~2026-12-02 16:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261202164956.49925-1-bugs@stellman-greene.com \
    --to=bugs@stellman-greene.com \
    --cc=akinobu.mita@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux@roeck-us.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®