From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417428; b=jUGO9nAxq7QExNsqmBvWkG7BkYwe9Q7oiUSrkrE+tfTDlLjKw6h/U9YVHP4yqu9OpzRp yssjHvooMswcu4Rq6snfv74foZO83+ZNBamSjqwsjCzDzecwrE0QN0IqSVRMnemD5+/6R SBTxKF3T5XP9Skuu09sr6HUL5pMGUyoHl1rtGFP6sEcFhB9NuKn85qezmZd3XISUuLkSe +07uIVD4VKKf/GcJpAIvWZ5sYLhGOp22ouoHB0INxQ0UN0G86a//pqjTkq+cRNx/g/FfW 9UHm1iyJEkinFOQSlNmPHjethe8Y0lMf2UC2eVGcIGxlBmkckXrWy7wXmQkhVGCPRMA== 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=rJ3tyxJr5ggmNJeUIUfTVwyS2vy+k+zbjyhhz5BTAxSrZy+hbF8QYfg5o7QZLF2Maopj pZLcP+QVJEe+JsBv+vSDH+jtCdGAr+Tw4W7LvegDA4j+erXXxL5/UDWTkGbPZcplys8Up C+uaK53luzhZK9c2zqTxp5W64pK6uuxs+HbIazKKG5TQ5oGibFUnksyBrKV/6oucWn/67 ngl8ZB4XLTj0nVCuXi/gQHEBkfjzEvx22/HiaXUzTPZ4ov/usrxk/PdjZpco0zcYb06Fv n0KhQm3eDjW7a+J/JcJYq7Ytq+SenwvxtyTIXiJ4oYU/9YGy71yhq+cjHpHjRg7RoFw== 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.176 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 748D6606A32C for ; Fri, 4 Dec 2026 20:50:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 748D6606A32C 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-f176.google.com with SMTP id 5a478bee46e88-38699cf08dfso1796906eec.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=l1iNnoxBPgIlArVJyzbEvjAqBjmkiSAUusGTyB4So/QtRD/4FsDYKriopeUDGcOxEU +jV+BpGmXnbGDisdKukiipCPyMdMoZn4HL0mWw9JcmpCgl8PuZWQGlnFbVnLnY9//rFv da/VV6DR3Da3lUHk0lpydQkyLqR+vgUHnE8DydT6EB/l/iEy44bG3InBKfKBAZTqsm/9 oNrjTowA0Txdy86RusR8AE4fLMNk/diwWUl8VBR6stseANZweG5UWnaKiLO3NqbeYKh7 l8pTrhlPQbgERVifIb9EgpzwRWTdyyYmoZBuFnUNNeAifTiGsh/Va/S36UQj1L0sB57a zOYg== X-Forwarded-Encrypted: i=1; AL+hErHzrFQkMWGwuNgKNR2zePF3LeE0XygufaNUcOzsw8EBTBINgyV86RsVLBb3A9meNPR+xcmq6Ss=@vger.kernel.org X-Gm-Message-State: AB4q+uFw6CKyVlrd9tXAHyb5iFZU2xhMsSIDXYIVs1AEElKwk+AXyM4Y k34bOrnSSSoRalEzeqBkbj+0we2+7H4fsIWjb1ShzkMpHYRA1BErxnjX X-Gm-Gg: AZFdTZejlW9VvSpY/yfagv54SD87gQkzq2UnOIu4UJ+JlA905EpG5XvGywsrrVO3vZW bUnISvhK6GRxfv6UjxhlzsZ9jqNvP9hJRWPwCRPyucVprSMe8+KcrPGqTQvsvNTqjXH2E0COcni G9hKy6MFsRpe99DV75I5jJTDfiaxL765IGcN1jy1vHqstr0YiY8/tBBvmb5Y6m6zf9wlKn3KKzC 6Uanl00WWhvYZD7EooArmnFspc5mshIbE0ke0V0C02sGzxtXYAGhQlohlyQqJHc7Y0H2X19UWVt elMPYkcoT4L2wfpw6CTodFX1mirlYDFLRvNXIaYe24aTzNmdJ6ubfioai2w55ryxNjK1wDpYEwy hX5BvxdojJPQqwvHmJA4croC2IshmoH+aJZRMxfBWbBFfxiipk7vxOfrU0+QjgQunhN8qiCLwNq aeWeFpmKLXIDulYYtDmPR4poV14Tmcq+8RxAOKKHKD/P3SxTO2Viwq7L4nn8BOGGGMuktorhpSn vFTnd9QG24vpxMeMxMDZME5fK14XJjOKmHJoveRysir2t7AF2ftoWL9+i/P2lQcQFvABNmmt52V 9shzOX2wqvzX7vj2nP6BzzC/tFQiLbel4IBoJ+i6auH6K+JMEwkI+ir7FUGnhq6P59k= 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: 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. 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