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=1796389323; b=dFiVPiU2Zde31rmoYa34aEtFDw/JCTbBD6IFHkK/xWeZxkWPxK+6xyZEi5OaFwMUlTxb +0n1Q8G5phMSOO2gTe2H6Vs4iIPt6IawKb/Pg4myfMm0Px8bsn/VLk3mOMKA8MChvqfT9 NgSTnWPsBeKqmJX/b/smp359ctigwfT8N4mmsAw2WvtYz/IWEUZBgwUYswNLfg+uivkfg 5rmF6jRwfJeK1efe0H2Fx0KADH9bBDLbm7rWBPUbgrCCMZwOkinUfBX+nenxbr0SP014V ro++LtM8cmCs0KWwvQZjDCaCMnQUBQByaYdzK48l6Ntbv/VavFL/hR45V048bU0LGSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389323; 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=TbllGcj0dVElstxf12/gqgdYc1YLJ19MmgF3K3c8Tz0=; b=Q+jJYwWH0K2PQn6GD7bCOfPgzuiMrCUKH3rF7xJHEi5rjcLiqK0U0P7ZNobCkAWOr6nU 1DIbIyU3M/b7UU9Eg1cRwN37lVSsIT/H8HG26/Rdj19irM67muKcUOjjUUS1KbPHivWUy K9VIfoycqLMJDWwYtsnH9/S1xx09amYPbLem8lhH3cnOplMg399YDdi1NT0JTPY7zUD2+ +iIRXfUEIhcHJK38+aoAPuZ4QBngES2kX4ppxbbe9OjIoQZBY8LZdn5XLv88HChUoLz68 SqJM6wIjG78PSazgmyAsiZdtXpiGCRMwD889W7z+32NWw3tkwMGhe6A3p5SjaRwDi/A== 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=Y6bveG1Y; 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 36ECF606A322; Fri, 4 Dec 2026 13:02:03 +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=Y6bveG1Y Received: by smtp.kernel.org (Postfix) with ESMTPSA id 747ED1F000C2; Fri, 4 Dec 2026 13:02:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389322; bh=TbllGcj0dVElstxf12/gqgdYc1YLJ19MmgF3K3c8Tz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y6bveG1Y/guuxS3Wc/lTOFoP9pzeLsEp8JTEb5d1vfIlGp5B+8hvpVwyvmjIr+geJ 4VLClx0DSjd8A+UJKHAiPEjtAELATHQKK51lXnA3ZIrT9okUfjV223+rpbTRJN/nn+ dRlHnIzQtl+H6m+qOK4hL+xvSBAmSQLW0L6jfRDc= 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 0949/1059] hwmon: (w83792d) Fix incorrect struct cast in show_temp1() and store_temp1() Date: Fri, 4 Dec 2026 19:08:00 +0900 Message-ID: <20261204100708.602340419@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 d4f7d626cc1a966dca930a5ba07e8c4739adceb0 upstream. 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 Link: https://patch.msgid.link/20261115080203.910033-4-zihengw03@163.com Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/w83792d.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c @@ -487,7 +487,7 @@ store_fan_div(struct device *dev, struct static ssize_t show_temp1(struct device *dev, struct device_attribute *attr, char *buf) { - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); int nr = sensor_attr->index; struct w83792d_data *data = 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 static ssize_t store_temp1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); int nr = sensor_attr->index; struct i2c_client *client = to_i2c_client(dev); struct w83792d_data *data = i2c_get_clientdata(client);