From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796389318; b=NIQVavkvHKG4+sQwIKR/Twl9esxkfTKVBVafVh1mNuWBPYsGRSiFfJ9C2fC9ZtAHWpB6 6LgFwmIJDcK9RvYVZQFoupggVHlmqM5TBfIfClWErIw/WkE8tb5d1j7zIXu3l9qogUfaM k6456Vea5XBdHuO05FQ8R6TCeMXylWjaAY0+nN9iJacL9gi944hpKlTAMstrtC0avVJwl lBBuw2XkjgTm3dCpm7WVHyyywM3bkpjSKaimx9BuTKai5Uo8JcpIRDpHw1OTjMxrGSrch AKebODjyjcAfcpdZP0Ps1rMQbMnyj6tJBsrzlLq9epKd82X1x7mY1DWM+upd4Q46Phg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389318; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=/wfE8kLaknctBXApj+jv2ojrBcyYeWWNAB6n5soua08=; b=IZ7NdaGd4A9/htXiv6ehgZlF6Y1HZqxvpVTKgoUrLwk+ANmyYvbx2UoEhA99Ej+82JCs o5kxmSDHojR5GGuFhZ141xqKuhK6S/4P7D7aO+PcY2iLF8t0ltZBjhYe+9kl0mXbGQgFB OrCi/j8QkJqUHebAXpuiFz+X0HCIclq2Gr+9kCHqwdKV18XVuzhF7fmACe4Enxv58xEb3 pv+cr5hP7uQys0nSjZH8EXle1FiXdOl+n4yaJbwAIYdmvpDQBgn3P91atNO917F6PdyFe A9xHkJ56C+Mk4LiZ/n7ryGw2bAPTeMDFZgDAPO6T5HGhv8h4f5aHR22ZdvvIvsUU3Fw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=aOf3zYZG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23665606A32C; Fri, 4 Dec 2026 13:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=aOf3zYZG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A28C1F00931; Fri, 4 Dec 2026 13:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389317; bh=/wfE8kLaknctBXApj+jv2ojrBcyYeWWNAB6n5soua08=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aOf3zYZG1+wl8vG0JRsTe5b4rw8aP/eJ3GxXby5zV8Pkw44nn1/Hl1u/zNckjpeMB L2CIbchPxmvVzhBxpCpqfUza4oHi9gA+f71DEmvs0hYIP3dSKBKbHpxx7vH1+ener1 Og+wXSmdO3/e992prg+fmiNqT6exIsqwnBcs6KY8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ziheng Wei , Guenter Roeck Subject: [PATCH 6.1 0948/1059] hwmon: (w83791d) Fix incorrect struct cast in show_temp1() and store_temp1() Date: Fri, 4 Dec 2026 19:07:59 +0900 Message-ID: <20261204100708.577755928@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ziheng Wei commit fb47eb0528d275362b01423ceb956e3ce1f9d715 upstream. 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 driver for the Winbond W83791D") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei Link: https://patch.msgid.link/20261115080203.910033-3-zihengw03@163.com Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/w83791d.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c @@ -924,7 +924,7 @@ static struct sensor_device_attribute sd static ssize_t show_temp1(struct device *dev, struct device_attribute *devattr, char *buf) { - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); struct w83791d_data *data = 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 static ssize_t store_temp1(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); struct i2c_client *client = to_i2c_client(dev); struct w83791d_data *data = i2c_get_clientdata(client); int nr = attr->index;