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=1796417428; b=sgKxzQxEj4bmqaEQRirJ7k20uLPalt2Pxke9i/Yppes6rYlnDMwTWcVPIpJljvU6z22J wGCosTChVQ3V96ccW12nfbABJoimT08KzixRMtF/LUjoVfQVBozsw1AgkrUIicmDcfSEj xqm2NShZrpvxB9ONwtowlHLJmh8z5ukki2AX44daFJYO24olstS0nqWO4C10pm/htBP1W u/pOAe1P/d6jYF8vkQRyviUexZmQOAaK6GMXuBFGnOy3Y+gp+dcW8Gca4wTzW8VwXcJ+h BeV2XV12knlwzhKcC1hs/itpZcjUeQmPzRIIK9LJ4GOgzrvdjwDWABz0IbsK0/+WbdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796417428; 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=q00KQtTi6odmkzs3vr7hpcdyM/+TQ03GWExEqHrAAyaIrEWLlp3pq9wzyHY2Uk6RpAgx ob/mjIC8i7aKWQBDrXB9dkR133JplEzUWvKOO2Uw5aVt0xSV7YwoZO62B2Orlwc9Ong+c v1xREC4hJbk5bELEWM+7sWnfWaq65cYofc3/zx0ksLejUYCcRYbEONZL4U8DnOBIISz82 Wp7GeU+57lI+MjeBU7V5PKQcgWTl8Wb3JgxEw+u8g7aZWgfQmtIHZe5MeUdy4adDObSRj NfgrbLkOpWBUGPclpvYHVfm2d0ZyHn9g4kPiU9Fba/CdnjYWK3iXkw+OEVN4yjk5yoQ== 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.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 7728F606A32D for ; Fri, 4 Dec 2026 20:50:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7728F606A32D 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-f173.google.com with SMTP id 5a478bee46e88-3874cf36e63so1860968eec.0 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=zPabSs24Dg4MYhffMp8IdGKBY6OwcJw1RNF9Iyyk5WHMZhrbdWV0l47l0nn3CPkKSd tOlEiiZWRRqHGKTlNxxo9o991zHsuyuZgAhrgNZLos1ElIKeVi9gJDIkz/8EPTHxSDSi nNGqk2dH3g2OGnyUj0kssr6tQVY6PJFo84fl+Acx/VdXGlRtwwqkzNYEngLxTMsjeVgZ caB55MObAFfOFmE3T6gEv3uLbYQ2JfbY3qXh8ezv4kg01j0KQwdm1waRdWVZev/oPyv0 Q9ELRH8lAvG2OvWKv/+udZuHfUCqVmeM5IfALjyBRoO60CyuQmKjgLmTNJ8EmRyqVJEW Bb3Q== X-Forwarded-Encrypted: i=1; AL+hErGSuUIdYuyTaolV3JtoLslg6im9qfh99TYDs8y6ii5i3b/M+iNrMxYoSjsH89B088hGk6yxfKE0uGLBt8Q=@vger.kernel.org X-Gm-Message-State: AB4q+uFi35EndUH4KD/+ho92nWFoqNbgMXVycPIBXLEpsEsnZvYpDlvY s1P/lNfYm4pcwTwEFLvDZ26D0UZx6Q/b2l7qzZ8v+epIrHE0l+1wmUbb X-Gm-Gg: AZFdTZfXwivyWD3wxsfz8m+B2h5Qg8ZBFu+Ssspu9Tt+1vrNooufI6SLolIa6iMiA69 YEDK9KfukrBZwQfpN0JYklp7UsKVOVM5EXWGGBgMmU7pkLNJGtspm9tZDSuUaJWzKl2Qm5/vP6e 4v/YS1+GkzxxQOs41s+pookUBnpC0/ahGFasUDawaFkqYxVMrXU+Hwl2+pbcV4EPqOs8ZrtNeFE 5bhvgYJqD71hHDCYcM12zOqdztu/s8Nf89J56pErbXG+UFC5K+tQwXYgkZzCFKEscqwN4SHYTr3 Bge/oM0tuW2a5nDGGM1WYQ83aQMo3656/sTtYUkv7xZbxhODA7Qi8cByxuN3BVs93iyTwFEwl+E ne2JWklgyhrt5uDD5Nun1JuIR+TaLggJeF52A2gwvF74qQlsDGlf6djE1WTmDTx6ELAGB4fa76o X/Z31XmNWV4pPCftf0ZzTGEFCyPDHGPCEs2pbvichKVtAORwhDJWsS7eD8qEYlvLgtK1RjG+Dkn 0ZG9iXovLPhrIDRNcfvt+yVhcR2CAg0WRyWF1CLSZvCwaZ5rPq0Jb2sJrWyQsnPY8Q4CxuBs8W9 W+s6zB4x4PYuhi72nMptb+1+DXx7epMTNv21/GYmyd5D8uGWNyHVCEz3Mp2jClKiNzk= 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-kernel@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