[PATCH 0/3] hwmon: Fix sensor_device_attribute{,_2} type confusion

Ziheng Wei posted 3 patches 1 week, 1 day ago
drivers/hwmon/nct6775-core.c | 4 ++--
drivers/hwmon/w83791d.c      | 4 ++--
drivers/hwmon/w83792d.c      | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
[PATCH 0/3] hwmon: Fix sensor_device_attribute{,_2} type confusion
Posted by Ziheng Wei 1 week, 1 day ago
These are the same kind of bug as the one fixed for nct6683 in commit
c4a01c2a80b2 ("hwmon: (nct6683) Fix incorrect struct cast in show_pwm()
and store_pwm()"): a sysfs callback downcasts its attribute to the
other variant of struct sensor_device_attribute{,_2}.

Both structs start with struct device_attribute, so container_of()
gives the right base address, but the index field is an int in one and
a u8 in the other. On little-endian machines the low byte happens to
be the same, which is why this has gone unnoticed. On big-endian
machines:

  - nct6775 (_1 attribute read as _2): every *_beep write lands on
    channel 0.
  - w83791d, w83792d (_2 attribute read as _1): temp1_max and
    temp1_max_hyst index data->temp1[] with index << 24, i.e. 16 MiB
    and 32 MiB out of bounds.

The w83791d and w83792d effect was observed on an s390x QEMU guest
(v7.3.1) with each driver probed against an emulated I2C chip:
temp1_max and temp1_max_hyst read 0 instead of the values in the chip
registers. The nct6775 platform driver cannot be built on s390x (no
HAS_IOPORT), so that one is based on code inspection only.

The three patches are independent of each other.

All three were found by LLM-assisted static analysis. The changelogs
and this cover letter were drafted with an AI assistant from my
analysis; I have reviewed the code, the fixes and the text.

Ziheng Wei (3):
  hwmon: (nct6775) Fix incorrect struct cast in beep callbacks
  hwmon: (w83791d) Fix incorrect struct cast in show_temp1() and
    store_temp1()
  hwmon: (w83792d) Fix incorrect struct cast in show_temp1() and
    store_temp1()

 drivers/hwmon/nct6775-core.c | 4 ++--
 drivers/hwmon/w83791d.c      | 4 ++--
 drivers/hwmon/w83792d.c      | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)


base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0