From nobody Mon Nov 23 10:30:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.2 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794729757; b=G8m1QuxHsk9xjUAvEKNTJHO4oTb05I2yqFnpL3+/wx0Bi9P0S48etlp1q5qH1xyF5NU/ 1BexxTXPuV0ziV0PctaWlxHP9BZu8H1SdXmw0gxb5IUfaoHRAaU0Vcg3OPbcjfZMS98rE K6CaYdyQr0ULBWHILgQD5jSF73SDUE5lCKpsRVRnJthHU2MZuW2I2pbKMJ1DScG1tHUuw Zgf/cTLgSxMdtGFEVcg3ylFT+/0UFQLhf7ajiJnt5jOrzE72rWvkT7jhzoqMRod4bW377 wMGKeiLIQ0B1yV42O3E/Go6rlvdl8ZkJARetl/Ttq0Hk38JBYo3ZCfPS7RH9DrRwiDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794729757; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=ZxrorjMF9l4wU2ezTb6rLOBDaUR1RrkpTkZgpgmuxl8=; b=U9fu1y6f8yNZ/y3AJMbgK4GV3MFhIcalo2Code8nbJGrtcDGhSJZiacLG4XOt++/g9bT K5ofZqn2hvjFCIbKfJ4Kt+yfbHZbdxMf4TNf04pRAKT+w1DNfT6zWBL4BXdHeyfpr3vRR QQ9vNUnvzuW3lTOyaafmse70xFN/kl/HhR1wquEaqJm9o5YmvNi0q5VG6NVgp5p1gtqfX iaY9cwtna2Cw7MmAN1o21/uIVWDOaD52nmNYMWQloNhVnNeNEvI5TR1uI/87ITmuUpWWz iPBQ3cN2NFtqY7BhB8AGx/oQ1jV+KsBlEV5F4Dn1jyLSoPyCqzn0g3nypcCrhIALkZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=PFD5OK1Z; arc=none smtp.remote-ip=117.135.210.2 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9299F606A8AB; Sun, 15 Nov 2026 08:02:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9299F606A8AB Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=PFD5OK1Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Zx rorjMF9l4wU2ezTb6rLOBDaUR1RrkpTkZgpgmuxl8=; b=PFD5OK1ZIwkz21PHI3 9s520MzodjHwq7O6fYCn1l/k5rsOZfbWkyWW7daSgX3E1rElBNbFYwk6YSXlxYoo o7FAteL6Ya6Mej673g8zy0MJEXlajtl8iQP5xsKHOWdEkBAwXUb8g4fPOY8AqPe/ 0CLFSiSzEQvj6Bk+h8XEQ1h5o= Received: from user-VMware-Virtual-Platform.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD3v4f8ZvlqxKXvHg--.43707S3; Sun, 15 Nov 2026 16:02:06 +0800 (CST) From: Ziheng Wei To: Guenter Roeck Cc: Marc Hulsman , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/3] hwmon: (nct6775) Fix incorrect struct cast in beep callbacks Date: Sun, 15 Nov 2026 16:02:01 +0800 Message-ID: <20261115080203.910033-2-zihengw03@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261115080203.910033-1-zihengw03@163.com> References: <20261115080203.910033-1-zihengw03@163.com> 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: quoted-printable X-CM-TRANSID: _____wD3v4f8ZvlqxKXvHg--.43707S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw1rZFyDJF47KFWxJr1kXwb_yoW5Xr1rpF WDCayFyrWDGas7WrWUAa17u3Wa9r1rAw1fWrnxKw1Skr15C3srXFyUG3WjqwnIyFs5AFy7 tryqqryxGa95JFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bbdb8UUUUU= X-CM-SenderInfo: p2lkv0ljzqjqqrwthudrp/xtbC7R7xQmr5Zv6qCAAA3p Content-Type: text/plain; charset="utf-8" On big-endian architectures, writing the in[1-*]_beep, fan[1-*]_beep and temp[1-*]_beep sysfs attributes in the nct6775 hardware monitoring driver always changes channel 0 due to an incorrect struct downcast in the beep store callbacks. The driver defines these sysfs attributes using SENSOR_TEMPLATE(), which initializes them as struct sensor_device_attribute (where the index is a 32-bit int). However, the sysfs store callbacks nct6775_store_beep() and store_temp_beep() incorrectly downcast the attribute to a struct sensor_device_attribute_2 (where the index is an 8-bit u8). Because both structs start with struct device_attribute, container_of() resolves to the same base address. On big-endian architectures, reading the 8-bit index field from the memory layout of a 32-bit int fetches the most significant byte (which is 0), rather than the intended channel number. This type mismatch causes all beep writes to change the beep setting of channel 0, regardless of which channel the user targeted. Fix the type casts in the two store callbacks. Not runtime-tested: the only big-endian machine available to me (s390x under QEMU) cannot build the platform driver (no HAS_IOPORT). Fixes: 30846993047b ("hwmon: (nct6775) Add support for beep attributes") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei --- Notes: The changelog was drafted with an AI assistant from my analysis; I have reviewed the code, the fix and the text. drivers/hwmon/nct6775-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c index 6e97e4f08..d423f058f 100644 --- a/drivers/hwmon/nct6775-core.c +++ b/drivers/hwmon/nct6775-core.c @@ -1859,7 +1859,7 @@ EXPORT_SYMBOL_GPL(nct6775_show_beep); ssize_t nct6775_store_beep(struct device *dev, struct device_attribute *attr, cons= t char *buf, size_t count) { - struct sensor_device_attribute_2 *sattr =3D to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr =3D to_sensor_dev_attr(attr); struct nct6775_data *data =3D dev_get_drvdata(dev); int nr =3D data->BEEP_BITS[sattr->index]; int regindex =3D nr >> 3; @@ -1913,7 +1913,7 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct sensor_device_attribute_2 *sattr =3D to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr =3D to_sensor_dev_attr(attr); struct nct6775_data *data =3D dev_get_drvdata(dev); int nr, bit, regindex; unsigned long val; --=20 2.43.0 From nobody Mon Nov 23 10:30:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794729757; b=ku6NaRLm19VMJzlOJ54ILvWmblj+NEExr0cU+czkVJd5VEe+ab0RiXHcsExV7g4WvVKf aYdNVLAtckq+VR7g0hogEsRHqZG8n52ctyPFm38cgH8tlDxGS219IQ24YxLiMqcaDZxIJ X/d59t9JWv60REPs4Ji2tqRf+ov2jnWxyAhsbJzB+JcQJYrRnYXc1pW0hJ9TLPzV5caQT cXjI69HjGKD8A+xZfgWWzLxM4veGyYTD5jy1/5WFOtfwqjx6uODOm9VXVqbOjfWvwsNRU oSdh+5zOKIcf979guWTz6G960icZBFs+LFXKWR3oRpLk42TzNfeGwfIuUGK3q5cf+QA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794729757; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=bdU7br1gy9EV9/tYTrttX+aGuzCg7r+AtUPEfTqRJ1I=; b=NJ5uOAvcnBq8XvUvEIZZ+Xojp9RsB7ObY1DuHuC7KfXbz3EHmTgndnJ7KEGrJPY18Okd wsazpKrH0f345XfBbUuQdQid7VrRImhBRpSKF/TFAF3nvPjR6u7KPqMnvxmnDihUlxTsU IZZDm54aaEA5ZrMyRF9ajmIR1J1iqlGfWmAvn1fGXWJ1jDsRdYZdohGJAvCndGOfSF2Lp Maunm/LyIJvkJWi6Tb+E0HlYkdQxTRb6FVRzCA3EMjusEt36fqEAy1yvxFTv69H/eKYjx eQIGBQZzVgby2FVnuSJx/CKTHa6Szhk9pYDRY0YR1n7x95YKQdrMzOd3hDFvO9sVSxg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=oGuIwSj8; arc=none smtp.remote-ip=220.197.31.5 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42EC4606A8A2; Sun, 15 Nov 2026 08:02:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 42EC4606A8A2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=oGuIwSj8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bd U7br1gy9EV9/tYTrttX+aGuzCg7r+AtUPEfTqRJ1I=; b=oGuIwSj8cLH/BI2sqm wETADnFgke0N+zgCjtPdJAp4uoZNg9b7lM9PyBZZgianPHSOGRKAX+ZdHPHPcdL0 Qq48ARHjVjoq8hRprNZ3+Uu6IWFn79dlTRYVM6NuWB7Pm1CHvkkP7UovJ7veorA+ 39l02JKXy4YhMg10oVuONXQL8= Received: from user-VMware-Virtual-Platform.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD3v4f8ZvlqxKXvHg--.43707S4; Sun, 15 Nov 2026 16:02:07 +0800 (CST) From: Ziheng Wei To: Guenter Roeck Cc: Marc Hulsman , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/3] hwmon: (w83791d) Fix incorrect struct cast in show_temp1() and store_temp1() Date: Sun, 15 Nov 2026 16:02:02 +0800 Message-ID: <20261115080203.910033-3-zihengw03@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261115080203.910033-1-zihengw03@163.com> References: <20261115080203.910033-1-zihengw03@163.com> 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: quoted-printable X-CM-TRANSID: _____wD3v4f8ZvlqxKXvHg--.43707S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxArWUuw4rurWfWw15JF47Arb_yoW5AF1DpF WkGa4Fk3yDJws7WrW7Za17ua4Ygr18Cay3Gwn0kw1S9r1UJas7Jas8Ja1jvw13Aws8AFWk Jr1qvryUWayvvaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07brsjUUUUUU= X-CM-SenderInfo: p2lkv0ljzqjqqrwthudrp/xtbC7h-xQmr5Zv+hegAA3T Content-Type: text/plain; charset="utf-8" On big-endian architectures, accessing the temp1_max and temp1_max_hyst sysfs attributes in the w83791d hardware monitoring driver uses a huge out-of-bounds index, because show_temp1() and store_temp1() downcast the attribute to the wrong struct. The driver defines the temp1_* attributes with SENSOR_ATTR_2(), which initializes them as struct sensor_device_attribute_2 (where the index is an 8-bit u8). The temp1_input attribute has index 0, temp1_max has index 1 and temp1_max_hyst has index 2. However, show_temp1() and store_temp1() downcast the attribute to struct sensor_device_attribute (where the index is a 32-bit int) and use it to index data->temp1[]. Because both structs start with struct device_attribute, container_of() resolves to the same base address, but the field widths differ. On big-endian architectures, reading the 32-bit int from the memory layout of the two u8 fields yields index << 24: 0x01000000 for temp1_max and 0x02000000 for temp1_max_hyst, instead of 1 and 2. data->temp1[] has only 3 elements, so the access runs off the end of the array by up to 32 MiB. Fix the type casts in show_temp1() and store_temp1(). Confirmed on a big-endian s390x QEMU guest with the driver bound to an emulated chip: temp1_max and temp1_max_hyst read 0 instead of the register values. Not tested on real hardware. Fixes: 9873964d6eb2 ("[PATCH] HWMON: w83791d: New hardware monitoring drive= r for the Winbond W83791D") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei --- Notes: The changelog was drafted with an AI assistant from my analysis; I have reviewed the code, the fix and the text. drivers/hwmon/w83791d.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 8bb457326..530935a6d 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c @@ -924,7 +924,7 @@ static struct sensor_device_attribute sda_temp_toleranc= e[] =3D { static ssize_t show_temp1(struct device *dev, struct device_attribute *dev= attr, char *buf) { - struct sensor_device_attribute *attr =3D to_sensor_dev_attr(devattr); + struct sensor_device_attribute_2 *attr =3D to_sensor_dev_attr_2(devattr); struct w83791d_data *data =3D w83791d_update_device(dev); return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[attr->index])); } @@ -932,7 +932,7 @@ static ssize_t show_temp1(struct device *dev, struct de= vice_attribute *devattr, static ssize_t store_temp1(struct device *dev, struct device_attribute *de= vattr, const char *buf, size_t count) { - struct sensor_device_attribute *attr =3D to_sensor_dev_attr(devattr); + struct sensor_device_attribute_2 *attr =3D to_sensor_dev_attr_2(devattr); struct i2c_client *client =3D to_i2c_client(dev); struct w83791d_data *data =3D i2c_get_clientdata(client); int nr =3D attr->index; --=20 2.43.0 From nobody Mon Nov 23 10:30:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.3 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794729753; b=n8xCwamyrHsjvS7asWNjWCNBYa6YRuQnxvY7Ihz9Kmyb2FYeJELN8DpYycxcI/3Lr59U Kq9YSW/uasiU0vR/3z9RC/Ww7Co5lDgVgJxvxXQUxuqgjqwAqJsEjLXXc31SLQrkeYWx2 2chLRVobLoS56PJRa6BIcbAcBf6Xy6ngHzdaTU37nrFM+cFqeyMmSewpI8ZUkD1Uyp+DO 67p/YqXYftEMY9F+vwimamo7LkQac3HIuiZVZpVlZBAahI8aBVWBcw0OdyMIu8q8+dF3y crYJ9RIF5ByAi8VbzwhjwAc9Qv8RHu7X/EXcuFxuycNM4xh/ZauS2tFDykMVKKK9IPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794729753; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=qIBe1IptJdEw3mbiQ59WdvqMuyWgbSIYKmhp3SuEzqE=; b=NQ4NOSDGKhbKmM1LCvc2psNmpKnbDr44veKAsmV+C2M9A1lt/XkOZ7Glna/kprqvQ82I xsOQGI3Xyn99RWAmThfQTQhP/KbMA7gENvbwxem0lG5T1oWNGp9iagx0WJPfWXuXMRUnU z/kyx72DCzhP4Cld23yYGLxqKztle0Tc9qtD/7eb087HofWMWOMWm9m9TNZDpOmrU3uUW l0tBV/yuth7Tlqbx/5yUqmuGLUa6PdNDZr6xtq3hhXCAwttp10KwrEv5qV8shfXnHmmD+ h0ETAFcNTktqW8Gbag0Lvls9hf3A4Xuu9Kg5/Lz6h1HIJkSElLANRS0tcoJuO2E1/kQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=f2xM5+4A; arc=none smtp.remote-ip=220.197.31.3 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68D0D606A31D; Sun, 15 Nov 2026 08:02:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 68D0D606A31D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=f2xM5+4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=qI Be1IptJdEw3mbiQ59WdvqMuyWgbSIYKmhp3SuEzqE=; b=f2xM5+4ADtDFI9vSU+ 2yFfp/aOFvBszez/p+L2uEIq5gSEeuEpy3MoQVXH4qmZq/lZY/cjiO3S2uKdMNcD JV5bYTQxI08Q67bM2NsTOo+P5LBmMhA4PZ0y2a3tEUwbrTAqbQdPtwXsZAe7YKil cTCbpHF2OV8SxPc21gm4USON4= Received: from user-VMware-Virtual-Platform.localdomain (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD3v4f8ZvlqxKXvHg--.43707S5; Sun, 15 Nov 2026 16:02:07 +0800 (CST) From: Ziheng Wei To: Guenter Roeck Cc: Marc Hulsman , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 3/3] hwmon: (w83792d) Fix incorrect struct cast in show_temp1() and store_temp1() Date: Sun, 15 Nov 2026 16:02:03 +0800 Message-ID: <20261115080203.910033-4-zihengw03@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261115080203.910033-1-zihengw03@163.com> References: <20261115080203.910033-1-zihengw03@163.com> 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: quoted-printable X-CM-TRANSID: _____wD3v4f8ZvlqxKXvHg--.43707S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxArWUuw4rurWfWw15JF47Arb_yoW5AF4kpF WkGaySk3ykGrs7WrW7Za1Dua4Ygr1rCay5Grn0kw1Skr1UJas7Jas8Jayjvw1ayrs8AFW8 Gr4qqryUWFWkZaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bxfOwUUUUU= X-CM-SenderInfo: p2lkv0ljzqjqqrwthudrp/xtbC7h-xQmr5Zv+hiQAA3g Content-Type: text/plain; charset="utf-8" On big-endian architectures, accessing the temp1_max and temp1_max_hyst sysfs attributes in the w83792d hardware monitoring driver uses a huge out-of-bounds index, because show_temp1() and store_temp1() downcast the attribute to the wrong struct. The driver defines the temp1_* attributes with SENSOR_DEVICE_ATTR_2(), which initializes them as struct sensor_device_attribute_2 (where the index is an 8-bit u8). The temp1_input attribute has index 0, temp1_max has index 1 and temp1_max_hyst has index 2. However, show_temp1() and store_temp1() downcast the attribute to struct sensor_device_attribute (where the index is a 32-bit int) and use it to index data->temp1[]. Because both structs start with struct device_attribute, container_of() resolves to the same base address, but the field widths differ. On big-endian architectures, reading the 32-bit int from the memory layout of the two u8 fields yields index << 24: 0x01000000 for temp1_max and 0x02000000 for temp1_max_hyst, instead of 1 and 2. data->temp1[] has only 3 elements, so the access runs off the end of the array by up to 32 MiB. Fix the type casts in show_temp1() and store_temp1(). Confirmed on a big-endian s390x QEMU guest with the driver bound to an emulated chip: temp1_max and temp1_max_hyst read 0 instead of the register values. Not tested on real hardware. Fixes: 1f8dae31fe8d ("[PATCH] hwmon: w83792d use arrays of attributes") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei --- Notes: The changelog was drafted with an AI assistant from my analysis; I have reviewed the code, the fix and the text. drivers/hwmon/w83792d.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 2de6d7b68..cba907713 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c @@ -487,7 +487,7 @@ store_fan_div(struct device *dev, struct device_attribu= te *attr, static ssize_t show_temp1(struct device *dev, struct device_attribute *att= r, char *buf) { - struct sensor_device_attribute *sensor_attr =3D to_sensor_dev_attr(attr); + struct sensor_device_attribute_2 *sensor_attr =3D to_sensor_dev_attr_2(at= tr); int nr =3D sensor_attr->index; struct w83792d_data *data =3D w83792d_update_device(dev); return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr])); @@ -496,7 +496,7 @@ static ssize_t show_temp1(struct device *dev, struct de= vice_attribute *attr, static ssize_t store_temp1(struct device *dev, struct device_attribute *at= tr, const char *buf, size_t count) { - struct sensor_device_attribute *sensor_attr =3D to_sensor_dev_attr(attr); + struct sensor_device_attribute_2 *sensor_attr =3D to_sensor_dev_attr_2(at= tr); int nr =3D sensor_attr->index; struct i2c_client *client =3D to_i2c_client(dev); struct w83792d_data *data =3D i2c_get_clientdata(client); --=20 2.43.0