Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409901; b=rjUNueg0xv152BfYOEmwJJbj0UpYWbOok1XZdLYph8zLils6sVcYp2JeN8KJA21DP/O8 QJ7m9gPFWZko2q5OJ0xtmueQvCZ56ZkxOT1l66fO41Zsee7PFQbs1aa0JWPD4FCxo/yW0 z7AKROT3zstkkqYauV+6sDaJlabAMiDN9LJSJcG6i7rTrBo/zlIMwbGDjQKFTO95N38Qk IrY35MBGApUAtwgROploSjhxmkKBHiJN8T4fXJyEKPYw9/xG+Rele/pLsFzPaEHLu/s3r fkALwlagHqSjMUJ2TijF5j4SP9SHmXvP6p6dF/o/5eXLHiOyjuQkwASaVuBzSDWFvog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409901; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=RMPE1Zd4jiHuy9CM2UIhLE/RN2UewCHwRpROQ6GlRXM=; b=1E1g003wNKcK0uupOlny9OFM3zMv6rsinBqHXNwJc28t7kXMSAKW2I17jP0W0haY0O31 Fm1wI1RqH+VZj/mP/u6W2y9wjTeKYv804jA/uvvu3UDYxqF/yjuStnbsXsRO2Doa2FJAy Dx/98qZDfvYX4kE1jUlwiSbRC5UdBguD6GiSTok39TkTtiJpLkGAdylJzcLq85XbUOGBa /QDJuD9g/SxvW+fhRtokyxKipCuZK+Z3V/QrWNfYBprnvNTyb00uMkpRFXeMlwVKw9akK PfABjXx37qXRZZjy/wIZPT26shLOpm56mXpUIh6AEMvW3SRjF9cU3/nzDJNDBQbB8uA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=z2wzcBAK; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A909B606A696 for ; Fri, 4 Dec 2026 18:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A909B606A696 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=z2wzcBAK Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-387486ad5abso1896713eec.0 for ; Fri, 04 Dec 2026 10:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796409900; x=1797014700; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=RMPE1Zd4jiHuy9CM2UIhLE/RN2UewCHwRpROQ6GlRXM=; b=z2wzcBAKGv/TW0gWPyqzf3H6AhyPdxHZGOa1lpy3Usj6qkSQK/Z/2R6xMzSLJVAf7j QYweIMcVNnioXNvrMVrxYlo0z905Bn5qICoKcVZG090RBBlhI+tC90NC4FcZj/RgBznW Lu3gk0pE15o3/hlNE9Kz88F7MXvSmk21yqmB7eMbx7THlm8LXs4aI9JCms0Wghiz5E2j M7zdQrgaJAgE43IWBHFrdOTtK6B0NbjXHipgiaHge67YMicW9Qfwgm+rplBzhe+AecUf 0KymzTsgwOyymdLiT/iGL9NLmA+z4bpw9qovCFIAdlsuiTwO+VIkEEfswmisOx0OD5ze Yh8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796409900; x=1797014700; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RMPE1Zd4jiHuy9CM2UIhLE/RN2UewCHwRpROQ6GlRXM=; b=Gsg+5oXJh9yAhvhEv97GcWe8c0hQzPU2gZ1tl381imlScN+9XTXf1bh68KHOiKagT8 M4ySv5N0F5Gs/yZsf8uyRMQt0hzz3NJSVBKPeAg+goPWbFA6ry2Lm2R2dULoc4YnmYaM zC5wY0gYmUObUcSwIGWDeD+iNY/Us3BeLbzoMMJp/qcCa+b9/ijeAiQI7z8hTGGHUvSU Jp1mHFzr8DN4d4nQBQ2TNRB8zCRaH8I1R5jYwSU6puM3lwgL3NtjlCTAFN6geSeckOZv IbiFbz0JPwg1C8Dj0MOlyy44rtc+ZT65wA8psMji3vVctGUvUFquETDE8Y6zO3TJ7s6j Ab7g== X-Forwarded-Encrypted: i=1; AL+hErE1QqVqbih1lq8h+W5x8yRAYQHOFwl3RLFbPPVMb552HzZ8cMW9EAEhH2lI8/pRI1siWLn+GQqU/v3HtQ==@vger.kernel.org X-Gm-Message-State: AB4q+uEfz7Bd/xeq/cpwMAy0UKVKjwuz4R0HPZGNcz7G+W94SoOu0UUy 7rujkXhg9cGwILwo6MpQo8s6Dmd+7cmec6m6l+/7fGLHFN5Nx0pX5Go1 X-Gm-Gg: AZFdTZdI1Hi5azzybhLxMFDm8MSPsFfXxL6z3AW8yg5FJmLZr43KLmhTKTsit9OMwsY QBH5Cu3PoHEhXEmMsNa+1VJ6J697zy5pGUQDVxjPlkmiAQOs/9Q+bJsLjfImmic6fCKzF2AXyOL pHaSfXqg+D2QGRvMDLOInhdLUewLc9fTzPD6q5O6DrbJZOAdN1TZWcVYN84hvJejbnOXrGfFr2E QEWKqxBsYFzHvRqisRLLZ4VT/p2HLWReOnE2ajd/0+i/F+NDIv8HYYdigrIFnPPTG1EujFQpYKF YkK/cQoh2vAYGf3Ti2rQzucI/DIXRrCbssSM1OAcmwCc9ASOi+nXDkgxFpnlojo7BRpp/Iylsau nllAxGtbgSPfsQ9mjAsgzixbd13bt+iAwZNaqAWimFaqAgteMV/KCtUcoSCqAuxVbZ21lzetSBf F+YbqzTMJrziLDSjkqgcRyr+yz2DhRFDFyd5iJ0I4XJXVq2Ac3O1YjGVvwLCb5bcwkKrzySFwVt iCw6fMk/d+WPO2HX5auv7Nq7RgsKVRk8qPab0HVzKN1xzCrQH8tlu9nP0VkkiclrC+zrwSUnE2m BWTsMo4/UNrlvPHH1c0M05gJmP0PqB03Ru7AdLJSLqzA6OUDBgGw2gYTqw13mDl73bM= X-Received: by 2002:a05:7301:5158:b0:386:f868:8caf with SMTP id 5a478bee46e88-3875216043dmr2311265eec.8.1796409899435; Fri, 04 Dec 2026 10:44:59 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38752204591sm11564522eec.21.2026.12.04.10.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:44:58 -0800 (PST) From: Praneeth Balasubramanian To: Guenter Roeck , Jean Delvare Cc: Frank Crawford , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [PATCH] hwmon: (it87) Lock the device while reading the temperature sensor type Date: Fri, 4 Dec 2026 10:44:47 -0800 Message-Id: <20261204184447.1685572-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit show_temp_type() calls it87_update_device() and then get_temp_type(). it87_update_device() drops data->update_lock before it returns. Since commit 6593eac89920 ("hwmon: (it87) Add support to detect sensor type AMDTSI"), get_temp_type() no longer uses the cached register values but reads IT87_REG_IFSEL, IT87_REG_TEMP_ENABLE and IT87_REG_TEMP_EXTRA from the chip. These reads therefore run without update_lock and with SMBus access enabled, while the comment above it87_read_value() requires both. it87_read_value() and it87_write_value() go through one address/data port pair. If a read of tempN_type races with a sysfs store that holds the lock, for example set_temp_type(), the address write of one side can land between the address and data accesses of the other. The store can then write its value to a different register, or the read returns the wrong register. Take the lock with it87_lock() around get_temp_type(), as set_temp_type() does. The missing lock was found by a static check that turns the locking rule in a function's comment into a Clang context-analysis requirement on its callers. Fixes: 6593eac89920 ("hwmon: (it87) Add support to detect sensor type AMDTSI") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by a compiler-based check, part of research at UCSB SecLab. The locking rule stated in the kernel-doc comment of the called function was turned into a Clang context-analysis requirement (__must_hold) on that function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every caller. An LLM was used only to turn the comment into a machine-readable rule; the report itself comes from the compiler. The patch and changelog were drafted with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64, clang 23, allmodconfig). Not runtime-tested; I do not have this hardware, and I have not observed the race myself. drivers/hwmon/it87.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index c6cdb04add1a..067a92716ea6 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -1398,11 +1398,18 @@ static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, { struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); struct it87_data *data = it87_update_device(dev); + int type, err; if (IS_ERR(data)) return PTR_ERR(data); - return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index)); + err = it87_lock(data); + if (err) + return err; + type = get_temp_type(data, sensor_attr->index); + it87_unlock(data); + + return sprintf(buf, "%d\n", type); } static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr, -- 2.25.1