diff options
| author | Ziheng Wei <zihengw03@163.com> | 2026-11-15 16:02:03 +0800 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2026-11-15 14:42:25 -0800 |
| commit | d4f7d626cc1a966dca930a5ba07e8c4739adceb0 (patch) | |
| tree | d7f66b23c442ae05e11f8522b2d0a4b74c9b9b18 /rust/kernel/alloc | |
| parent | fb47eb0528d275362b01423ceb956e3ce1f9d715 (diff) | |
hwmon: (w83792d) Fix incorrect struct cast in show_temp1() and store_temp1()
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 <zihengw03@163.com>
Link: https://patch.msgid.link/20261115080203.910033-4-zihengw03@163.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'rust/kernel/alloc')
0 files changed, 0 insertions, 0 deletions
