From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417427; b=lwHUcuFjR4yZppqc/0VZTRHecse2thThZmbCGS9lipQEpxYYGzD7ZC/xLvMWSgaADKD+ zj4vEUJ/Xt+Bh5bUlHPLOXIBwO/Zsrwkj7UDMudRK3KBTfJTNgvby0U0rrNqTzykyD9R2 GsqR85tUZDsC2qCYo/fVSbdTR+2Y8H/Ij8L/lcEPgdn26WqSEX1Ec46DVGJeuOhOT+Fme FD4UgIhMVeSqJXc//61szoTlgpkXXwyKpTGlAlSslKPtnrhIAd9E+9ObSCNulOgj5s9tZ nljqENwMloi/aei891ldu7WICMrZFxKwDrqhxgdLooSNjiQHwhhFd/vFe8E4z1u68Ow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796417427; 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=+Ogk/x0TOK9vzvY9VSRR0t11vpu5+fwmMdl7vQOvLfA=; b=NrTF/5ASr/bPTWJkZjUN6Xum8UZzdcdZdoGGeX75P3mAvlkqJDbhh7ewtHf+Kilbl9YI 5Fd6nPxILh1pzq7rY4XCYt06aF1kl5psVsw0G68aD8XEH6NHG19nAmATVdpCFNZkrS3ML Quk9oYLeWFfSLqz4I5a1zfbmTZRDytAkxrBY0ljkd9hX58v5w9VMvUMZ4HLEr6DJLhlia acUN3n9Bdu18gKHPIj3qjcnqDxH+TQ+XxE/G9zwG3DP3yYckiB7N8sRSGuX07QLwne/VD RO3OaWFfHQXInxf+JRfZVrZ1c6+sY240S6DZYUredRobxvymMGjozOnbDXCaZy1La8w== 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="xwessY/o"; arc=none smtp.remote-ip=74.125.82.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 7117A606A322 for ; Fri, 4 Dec 2026 20:50:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7117A606A322 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=xwessY/o Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-38699cf08dfso1796907eec.1 for ; Fri, 04 Dec 2026 12:50:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796417426; x=1797022226; 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=+Ogk/x0TOK9vzvY9VSRR0t11vpu5+fwmMdl7vQOvLfA=; b=xwessY/oQOKWGEHVJZaTjD7U7eCZcr46c8S/lFGSNmBTTji9M0JM0Te53ZvYC5+d1/ +eV0kYW0nT5E6WyTYV38x7f3xfqxz/ZZt4JtIpki1qz+BuZWUfe7bWmG59dXYcsPMIJH zLuqMhH9G4QUnK3ZlnG/k/XyG5XraqffuIm4skWG4y0XJy+BfD7gGpc4srVb+1xC0BOh 5onirsYH0PB7QqEAdrebEBOBRL6mTE/lZoHZS2+rVbtonYjOuqC3xyMYlNa1gfLzv83g mM13BSENTvLsIjhYDgwkwu15N22uPunTgtca6PT3wEqKdwyNqpjsPlafFvCFZ7ghaHvc ZUUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417426; x=1797022226; 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=+Ogk/x0TOK9vzvY9VSRR0t11vpu5+fwmMdl7vQOvLfA=; b=O5NC9bomV2/MyaoTdHY3qsktaiOSTDJ4gTchIRuXDcBmwPudvPzsMBBYESxyjF1YmW Vds2pFgyu4bZl0lGw3yGcMV0B+80P/q2tJcoxjhIMJxw6LEkhDVvIZqdqO71pjhOrd6l Zr61sGNS0yGVevwM7IItRZSjgEyG4S5IIDpaSahm/muoNMJGKOtRwQldAtsY3Rm6IHCV BtcOYoWmZyxSTBHM3NFI2FNghPAoeoRNYJ9vAUyaldSzerluAPgMQx+6znpCoAQeTr2x Ngyyn9KG92Zh5AyzbTAZILOxfKIuaAYcc4vcdqsrm+DrFsNONLz00T38wFNIRvxu6bN0 QEig== X-Forwarded-Encrypted: i=1; AL+hErGEG7H+rw3gGUxUnTRONtnaLWu2tzvRI1VCNaGyELmbiteWpIAuWtlDTb7sv9EDX2Z+lm4ComV73/yxXw==@vger.kernel.org X-Gm-Message-State: AB4q+uHr3+JFfN+fSncKb4BTrb19Gz7EcAvECC5J7CrtdXIOLVKQ9+7i YiHPlLoM0CymXpHeaSWiVlovFMkbTX5A4R7BMbSJMM6cmxD0OV5L+fJw X-Gm-Gg: AZFdTZezNJOnsOm1zt9ePdyA8v4W/2Z2F9Ve+VW9Zu3gftUt09iOeD+KYm/6IrlYen8 WX19ZeyE2zGrjLlBjnmsO/GY7sFalP4Yzp83aDfmkSYne+KRLZzvOCEJ6Gt9M3111u5grYp9Eji OZgWRt1ZsKU88qV/lF7p5DpR8krtqJV5o+TS/aklDuUd4SrtH+MYEpnNa07l031iUolOoPhIV+Q 2SlDjeuN+3+j2ueN4o4SvDNhGIsa0hIEsdsMBhsU94OC8+0m1EqCYaVx2/WC+9fNVK2apUivXZ/ EGozgrfSfN3Z+gWxxWd3X5KAFPXeaXnsdglDUUlQN5pY3zZPlqCTULtG8Rnna2FXVS9PkWdCu23 KD6MAzwiecsi2VelcSKmF9N8ctwoNj59l/PUzYdFp9XnvzpXcgZq+UY7kiseCyoAgWmkQFT13kL Y1cs9iAgcnki8U43RtXK6Q/N9GbMtigeJyvvrfySFW47RsRAv5ay0V75QsyzE/kxjK1XfezK7rZ uzgMtKB736ivlGQy8hALIikCAQes+Ex3ijsZi+kKIXwcexJyQBrmRbsKyeGkbPlxHNRP2sCnHiU kxvTy8+jwvBORf+JK5kkbo6tXScEmn7z3jcCtQtOUdIF7Zczuu0qgfK4L/onqegkLM8= X-Received: by 2002:a05:7301:1699:b0:387:51ce:d2df with SMTP id 5a478bee46e88-38752162e08mr3796919eec.26.1796417426233; Fri, 04 Dec 2026 12:50:26 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bdedbsm10757384eec.12.2026.12.04.12.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:50:25 -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 v2] hwmon: (it87) Lock the device while reading the temperature sensor type Date: Fri, 4 Dec 2026 12:50:16 -0800 Message-Id: <20261204205016.1788907-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. get_temp_type() uses none of the cached values, so also replace it87_update_device() with dev_get_drvdata(), again as set_temp_type() does. This avoids taking update_lock twice and an unused refresh of the cached registers. 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: Changes in v2: - Use dev_get_drvdata() instead of it87_update_device(). get_temp_type() reads the registers itself, so the refresh only took update_lock a second time (Sashiko review, Guenter Roeck agreed). 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index c6cdb04add1a..74642aa319dd 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -1397,12 +1397,16 @@ static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) { struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); - struct it87_data *data = it87_update_device(dev); + struct it87_data *data = dev_get_drvdata(dev); + int type, err; - if (IS_ERR(data)) - return PTR_ERR(data); + err = it87_lock(data); + if (err) + return err; + type = get_temp_type(data, sensor_attr->index); + it87_unlock(data); - return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index)); + return sprintf(buf, "%d\n", type); } static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr, -- 2.25.1