From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409901; b=2WcedEVpYo23Awy2GuL6EVaegnHB2+T1epGp8LIU52tutRlda983LCECbmBFq6wiOc7h ClDbTL0iXSnQys55rFSfPPJOPmuRXL6ygjCEolEGj10WgwH8RopDhrq7FvPQjub/vMwsv xJHvhQCGXhONyWwHXvnVnJh+ZFK0NgT4lfdSDLbfNH+aqHQpDz/Q3jliPHVa2LxJto/TG CnG5GNvx62qDfd9drX0ODjHyYbj5VBN36mNRDIMRG/bHVqvfzjD4OeWOuCI9FwLFOoB1j 6qQMHOi8VAj7JFhXl4jvSDzT83xTNK7XiQpxbFzi+qEsFsZbaJw/s6tihlTg6+FQTag== 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=RR9LW+O7kRpm+71Enf+hNqdFG4T9lBpg05OA0YZmgHjKHvi3OJqKSgcCDmS8JS5JeETy q3e9ow8EPxA1Vxc1QCYxn5EqHAv3G/i36T84EQbos4rv70htK9YRqcEEl0xH8VpPcd3bS oKCDwCSSBACQ2W2C7ZGr+JRnSlQotTQG9mBh4lg1m98iFKK1EoGflof9I3+9xYXud4Zqj sWySYnluLpjgsdv8JiMuB5/N1WG9bAaarivqi3R64kZNUvQcqTlJ5TEFWIZey3YSAQI/b gfCG3+JKddap7QS7eJ687JbHLxYOLo6P2QOSzngGNrYuxt9vox8v67rwHFYjXa3tQHw== 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.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 AB028606A698 for ; Fri, 4 Dec 2026 18:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AB028606A698 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-f172.google.com with SMTP id 5a478bee46e88-38190551625so1443923eec.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=n2FnSVAmUUhu/E9XDCofMuGKd8hqSBw730GnO2nHvtovKumRYXZom604YyIWDQXlA/ ZMNAgVmCpi/RadWUuMP9c9PG1gBt27kgK4qNRNYRtKFs8yiKpGhQWgywi+3JY3CAQTep 1aHX417QEEjJzbcioLI4NuIpndfjmJbtCPgGQs/nH2w3EWeX0JmRQCvzEH+NNOAcd+7/ 8k9klVHRTBDykAa9xeccto5BklhgE4gu19rB7488gMGdQPMoZ469ZKE31uHoVGhTiSDu tQ6JDAUFiv0nVV5QJeRvITNbBcHchVGG3/5tDRBI6foPTa/QkbG1vrlPCNg5a8ZI09wt fr3Q== X-Forwarded-Encrypted: i=1; AL+hErFGpwl0/bQvcU7Bb9D248YEeLmjOmGbd+RnKc41sdj+/A6l61c+5BnMFhAeB3cC+qJAyHt+7Lh2Lcrpkng=@vger.kernel.org X-Gm-Message-State: AB4q+uFZBNuo4X+JBoiWm1xek1nd+XYI9tGJBEz4gosniKiPF1TNTwui RPkFq33BGh9G7Dda226dYAR4+pXghlth1+SG93yXoLUry0eBK4n4bNF2 X-Gm-Gg: AZFdTZc//068zWV1Y7p9BRK5Svaoy8ujogcVPMhCktkjw02mzomEXtz49ZZFGSQuX0X ObQ+g+xJOZg/LaXShKJl4A4mMN03Pyg9P8oBKkrEyhlRLRKspv0//7mlmDl50jTTrDMd3u7IYA2 h24PY4dd0+vQFG9nSMne024gM/Tqscm1JqkCfScqlaM16mqWphnDcn40RZvqUVGeoA3DXnKL9vf oqoJf3Vza7vZf4ED5LXe4mrH3H9bMZZtZSX96SMQOGQR5Hrj2SrHUdT1KGrnEsHRtFxqtUQ6MUg gGyyomkF/+97WcGL+5+DX1A4nkqeAwMxSwyZnSdnO/L2Qt7sAxHMcFjQmykTEmOiaxYcO8Jy38M j7w+wyYf6IpWMh3n2Co/JlcWV5CjQYzksN+/9jpSImveBQb9AWUHD+4UYrTU0qJa7+6gngZpgYN bTbgyOLtCWRi7078zx1sG30T7dRMN27nfS8DbWisQn45Aj4vxVHX7U/mjvnfoekPmT3TSDYVyum vRx3M1BdOcBy5aajeoFlxbNPDCYTrWMSt8OGoT8gS6iLzcEmVZU1BJTbl6MkEq5Aa3YOJfMIkM6 ru9uzllluWZ5nyomtzZMCaMzn+MIr33paKBgisIB+vxX/C3b64xfC573ZyB80IT/Kzc= 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-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. 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