From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409901; b=t0F1PShQ8dSmERuDfh0YQWcsv632c+Hhvce/LYB141wGGAeF6ARF2UbeGXZBtWoBLb+Y iQiJ29wAwTfJHLzvFWODe6K1eWvtg5X690Yonmiq8WdXaetP+GXOcoDO3ybOuUwZbzvGF xCuPFUiRqMMQFcSI/0x1ShnuzgYTqpnEAAe3y4dHGQXVWqvoYH1zuNUIVbuMYGgea+w4u FYfx1UpEwySFgiJmDdVHgCpTPCcXW81eeYOorLPMC4teTPfDf6HrzX40h7wjXIr7mMX6r RljJy9c7TI5CdhcOQqt5zETQIr4KQpWa8RTb+AI5BDmjyIzMkRXPHpbXCcwxPX+iGFw== 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=XdQxvmoEZl43vL1EiVuuqfPBI/cEkAOTm0DaqaITgtGjSDGs/kAAhvaICfUvbFgcRZ52 t+V+IMjNxdIshW2/ajRz/XT1DNhhCOvELacFzEPq38xxHBqJZOFkz5tkhyZfwikyez4KT itAcX2wF1G5QMW5eyV3J0XgBGUXmep/mGdDthDHUqYhH5W9JaJbmNaj5m3IjHjG13a7uU ZWq6BgNCIsFXXPvC76uOpqg0xu04ARgP4PWVdwJJGf5jkeH1RJHjuwzpWoRuRVcZidrfR elqAuPbtOYGbZWvusJSgOlsgea1ZSmSOXzfesE5XK6vXz+1nnxdzk7gPSNNsF493puA== 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.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 A9380606A697 for ; Fri, 4 Dec 2026 18:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A9380606A697 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-f173.google.com with SMTP id 5a478bee46e88-38190551625so1443924eec.1 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=kDCfKWxbm7PQX/yq0fwt92pn6uJCeb3OkXk16U110ukHrIUK5cCB+QfEjHGuTaTtq3 qSwKrw5Mxok4rVR87PC/cvCwHP8lMReHzBrnqVNTU0eJzaWZFggtCBeyUfhUV7xouwXM zZNqZJi+4ETa6pfTeGzMnl6zRyr2870A3+VuRKTxD49o1nkXpATKQ/oX12pwjwrPbRa5 vDj84FbOAqvErn1cIr1D8OyrYT6J0L2RT3L4EMw5aZqXaJ/Q696LGuqJGAi1ewQ81h/7 ljHSM0wpDz3YRICZQspzO/iENT34MF7ICkg8W45Ii4VeVWjN1cLOWKWkUw7R183UjJYj cg5w== X-Forwarded-Encrypted: i=1; AL+hErFoZK3M2eTjazLbrM06DVrOoQwdT7n6IEOLNXcC7/Vp+6HEwOj+hezv9UN1bX0YRdAyIOJLeYY=@vger.kernel.org X-Gm-Message-State: AB4q+uFAdoRinIgP/hXNizpqad5xcFGcnW60HjCQ9Poa+D7qvxonIeRr gYfHL7ezcVFRDPQMbvUWKYznwfDLK0edkl76jgGBYVIXYoloNVMkZwIP+pEe9Pp1 X-Gm-Gg: AZFdTZfG9n+mtiQ5L+QUAykqXUzYkroizUp1x7t/iI3UklygGYjCjtkYGP0JGlZBgxx fv4AUfEPl77pRqrDeMBXRJ0raNMEiSlGKzYDdZCBAGJhAmr7HS+UqVFZWKkBR/Uta6+bFF3oswd I71c99uVcIfEan+34z4Nb1KLPgMWAAmACyoO3fslZF4lvNmHzjg7Cwq7BOcMC0DkVW4+wGKYZ1R +uwPIrw/+qLj7AKgX30lmCL2m4BAR7k93arcRc7jecw6YuogXhUdQJ2V8CtUN4mC15ah/YzXQbQ bH5i8EsYfgId0bqXHCmfVTQ12qy3F9ntXnWOQSqY7PCqUHCVJzaIoEKRJYroQKpr766NwoegMCN 5nE+Xrxna4HvSLGG7JlkXdLedPgz5/J3yNH59h6csa4vA6wwSFNlJWkPQRM7+HilMVjUGcQuA1Z U8UHi5RWvlElATz5kcOXeys8Z3nm3E74Kl5IooFZzViOll0N+B1QvffRM6CP74h9PK4fI8Gr1i9 4If4w1S06buOAj5FTjqteyFHG4zphKJnnDgq2dtwRX4u4c3PlYJ82eOBY3XR3VPvOvEUG4JFqx7 uWJIAlYxxYtoVVGidpnHcYh7urtMXyjKmshWeKJA6zCQlFaAzHQ8DfDruEvw/T/vTxo= 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: stable@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