drivers/hwmon/pmbus/adm1266.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
Five pre-existing bugs in the adm1266 GPIO path that all landed when
GPIO support was first added (commit d98dfad35c38). Each is
reachable any time userspace queries an ADM1266 GPIO/PDIO line via
the gpiolib char-dev or sysfs interfaces, or reads
debugfs/gpio-<chip>.
Patch 1 caps the PDIO scan loop in adm1266_gpio_get_multiple() at
ADM1266_PDIO_NR (16) instead of ADM1266_PDIO_STATUS (0xE9 = 233, a
PMBus command code that ended up in the bound by mistake). As
written, the scan walks find_next_bit() up to bit 242 across a
25-bit caller mask, reading out of bounds and -- if any of that
incidental memory contains a set bit -- driving a corresponding
out-of-bounds write to the caller's bits array.
Patch 2 drops a redundant "*bits = 0" reset that sits between the
GPIO and PDIO halves of adm1266_gpio_get_multiple(). As written,
the GPIO bits the first loop populates are immediately discarded
before the PDIO loop runs, so any caller asking for a mix of GPIO
and PDIO lines sees the GPIO half always reported as 0.
Patch 3 adds the missing "ret < 2" length check after the three
i2c_smbus_read_block_data() calls in adm1266_gpio_get() and
adm1266_gpio_get_multiple(). A device returning a 0- or 1-byte
response would otherwise compose pin status from uninitialised
stack memory and leak it to userspace via gpiolib.
Patch 4 moves adm1266_config_gpio() past pmbus_do_probe() in
adm1266_probe() so the gpio_chip isn't registered (and reachable
from userspace) until the PMBus state the GPIO accessors depend
on is initialised. This is a prerequisite for patch 5.
Patch 5 takes pmbus_lock at the top of adm1266_gpio_get(),
adm1266_gpio_get_multiple(), and adm1266_gpio_dbg_show() so the
GPIO PMBus reads can't land between a PAGE write and the paged
read pmbus_core does in another thread.
Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
---
Changes in v2:
- New patch 3: reject short block-read responses in adm1266_gpio_get()
and adm1266_gpio_get_multiple(), so a 0- or 1-byte response from
the device cannot leak uninitialised stack memory to userspace
through the gpiolib interfaces (Sashiko review of v1).
- New patch 4: move adm1266_config_gpio() down past pmbus_do_probe()
in adm1266_probe() so the gpio_chip isn't reachable from userspace
before the PMBus state the GPIO accessors depend on is initialised.
Prerequisite for the new patch 5; without it the lock acquired by
the GPIO accessors would race adm1266_config_gpio() / pmbus_do_probe()
setup.
- New patch 5: take pmbus_lock in adm1266_gpio_get(),
adm1266_gpio_get_multiple(), and adm1266_gpio_dbg_show() so the
GPIO PMBus reads serialise against pmbus_core's PAGE+register
sequences (Sashiko review of v1).
- Patches 1 and 2 are unchanged from v1.
- Link to v1: https://patch.msgid.link/20260516-adm1266-gpio-fixes-v1-0-38d9dd39b905@nexthop.ai
To: Guenter Roeck <linux@roeck-us.net>
To: Linus Walleij <linusw@kernel.org>
To: Bartosz Golaszewski <brgl@kernel.org>
To: Alexandru Tachici <alexandru.tachici@analog.com>
Cc: linux-hwmon@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-gpio@vger.kernel.org
---
Abdurrahman Hussain (5):
hwmon: (pmbus/adm1266) cap PDIO scan in get_multiple at ADM1266_PDIO_NR
hwmon: (pmbus/adm1266) don't clobber GPIO bits before PDIO read in get_multiple
hwmon: (pmbus/adm1266) reject short block-read responses in the GPIO accessors
hwmon: (pmbus/adm1266) register the gpio_chip after pmbus_do_probe()
hwmon: (pmbus/adm1266) serialize GPIO PMBus accesses with pmbus_lock
drivers/hwmon/pmbus/adm1266.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
---
base-commit: 70eda68668d1476b459b64e69b8f36659fa9dfa8
change-id: 20260516-adm1266-gpio-fixes-dbdb9c10a4c2
Best regards,
--
Abdurrahman Hussain <abdurrahman@nexthop.ai>
Hi, On 5/16/26 16:18, Abdurrahman Hussain wrote: > Five pre-existing bugs in the adm1266 GPIO path that all landed when > GPIO support was first added (commit d98dfad35c38). Each is > reachable any time userspace queries an ADM1266 GPIO/PDIO line via > the gpiolib char-dev or sysfs interfaces, or reads > debugfs/gpio-<chip>. > > Patch 1 caps the PDIO scan loop in adm1266_gpio_get_multiple() at > ADM1266_PDIO_NR (16) instead of ADM1266_PDIO_STATUS (0xE9 = 233, a > PMBus command code that ended up in the bound by mistake). As > written, the scan walks find_next_bit() up to bit 242 across a > 25-bit caller mask, reading out of bounds and -- if any of that > incidental memory contains a set bit -- driving a corresponding > out-of-bounds write to the caller's bits array. > > Patch 2 drops a redundant "*bits = 0" reset that sits between the > GPIO and PDIO halves of adm1266_gpio_get_multiple(). As written, > the GPIO bits the first loop populates are immediately discarded > before the PDIO loop runs, so any caller asking for a mix of GPIO > and PDIO lines sees the GPIO half always reported as 0. > > Patch 3 adds the missing "ret < 2" length check after the three > i2c_smbus_read_block_data() calls in adm1266_gpio_get() and > adm1266_gpio_get_multiple(). A device returning a 0- or 1-byte > response would otherwise compose pin status from uninitialised > stack memory and leak it to userspace via gpiolib. > > Patch 4 moves adm1266_config_gpio() past pmbus_do_probe() in > adm1266_probe() so the gpio_chip isn't registered (and reachable > from userspace) until the PMBus state the GPIO accessors depend > on is initialised. This is a prerequisite for patch 5. > > Patch 5 takes pmbus_lock at the top of adm1266_gpio_get(), > adm1266_gpio_get_multiple(), and adm1266_gpio_dbg_show() so the > GPIO PMBus reads can't land between a PAGE write and the paged > read pmbus_core does in another thread. > > Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai> Sashiko reported a number of additional problems. As far as I can see those are real. Would you mind fixing those issues as well as part of this series ? Thanks, Guenter
On Mon May 18, 2026 at 3:08 PM PDT, Guenter Roeck wrote:
> Hi,
>
> On 5/16/26 16:18, Abdurrahman Hussain wrote:
>> Five pre-existing bugs in the adm1266 GPIO path that all landed when
>> GPIO support was first added (commit d98dfad35c38). Each is
>> reachable any time userspace queries an ADM1266 GPIO/PDIO line via
>> the gpiolib char-dev or sysfs interfaces, or reads
>> debugfs/gpio-<chip>.
>>
>> Patch 1 caps the PDIO scan loop in adm1266_gpio_get_multiple() at
>> ADM1266_PDIO_NR (16) instead of ADM1266_PDIO_STATUS (0xE9 = 233, a
>> PMBus command code that ended up in the bound by mistake). As
>> written, the scan walks find_next_bit() up to bit 242 across a
>> 25-bit caller mask, reading out of bounds and -- if any of that
>> incidental memory contains a set bit -- driving a corresponding
>> out-of-bounds write to the caller's bits array.
>>
>> Patch 2 drops a redundant "*bits = 0" reset that sits between the
>> GPIO and PDIO halves of adm1266_gpio_get_multiple(). As written,
>> the GPIO bits the first loop populates are immediately discarded
>> before the PDIO loop runs, so any caller asking for a mix of GPIO
>> and PDIO lines sees the GPIO half always reported as 0.
>>
>> Patch 3 adds the missing "ret < 2" length check after the three
>> i2c_smbus_read_block_data() calls in adm1266_gpio_get() and
>> adm1266_gpio_get_multiple(). A device returning a 0- or 1-byte
>> response would otherwise compose pin status from uninitialised
>> stack memory and leak it to userspace via gpiolib.
>>
>> Patch 4 moves adm1266_config_gpio() past pmbus_do_probe() in
>> adm1266_probe() so the gpio_chip isn't registered (and reachable
>> from userspace) until the PMBus state the GPIO accessors depend
>> on is initialised. This is a prerequisite for patch 5.
>>
>> Patch 5 takes pmbus_lock at the top of adm1266_gpio_get(),
>> adm1266_gpio_get_multiple(), and adm1266_gpio_dbg_show() so the
>> GPIO PMBus reads can't land between a PAGE write and the paged
>> read pmbus_core does in another thread.
>>
>> Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
>
> Sashiko reported a number of additional problems. As far as I can
> see those are real. Would you mind fixing those issues as well
> as part of this series ?
>
> Thanks,
> Guenter
Sure -- v3 (sending shortly) folds in everything Sashiko flagged on
v2 that isn't already covered by the "buffer-bound and timestamp
fixes" series you applied to hwmon-next:
- New patch 5: register the nvmem device after pmbus_do_probe();
same probe-ordering hazard v2 patch 4 fixed for the gpio_chip.
- New patch 7: take pmbus_lock in adm1266_nvmem_read().
- New patch 8: take pmbus_lock in adm1266_state_read().
- Patch 1 commit-message wording fix (Sashiko corrected the
"27 unsigned-long words" arithmetic; no code change).
- Reviewed-by tags from Linus Walleij (patches 1, 2) and
Bartosz Golaszewski (the rest).
Thanks,
Abdurrahman
On Sun, 17 May 2026 01:18:46 +0200, Abdurrahman Hussain <abdurrahman@nexthop.ai> said: > Five pre-existing bugs in the adm1266 GPIO path that all landed when > GPIO support was first added (commit d98dfad35c38). Each is > reachable any time userspace queries an ADM1266 GPIO/PDIO line via > the gpiolib char-dev or sysfs interfaces, or reads > debugfs/gpio-<chip>. > > Patch 1 caps the PDIO scan loop in adm1266_gpio_get_multiple() at > ADM1266_PDIO_NR (16) instead of ADM1266_PDIO_STATUS (0xE9 = 233, a > PMBus command code that ended up in the bound by mistake). As > written, the scan walks find_next_bit() up to bit 242 across a > 25-bit caller mask, reading out of bounds and -- if any of that > incidental memory contains a set bit -- driving a corresponding > out-of-bounds write to the caller's bits array. > > Patch 2 drops a redundant "*bits = 0" reset that sits between the > GPIO and PDIO halves of adm1266_gpio_get_multiple(). As written, > the GPIO bits the first loop populates are immediately discarded > before the PDIO loop runs, so any caller asking for a mix of GPIO > and PDIO lines sees the GPIO half always reported as 0. > > Patch 3 adds the missing "ret < 2" length check after the three > i2c_smbus_read_block_data() calls in adm1266_gpio_get() and > adm1266_gpio_get_multiple(). A device returning a 0- or 1-byte > response would otherwise compose pin status from uninitialised > stack memory and leak it to userspace via gpiolib. > > Patch 4 moves adm1266_config_gpio() past pmbus_do_probe() in > adm1266_probe() so the gpio_chip isn't registered (and reachable > from userspace) until the PMBus state the GPIO accessors depend > on is initialised. This is a prerequisite for patch 5. > > Patch 5 takes pmbus_lock at the top of adm1266_gpio_get(), > adm1266_gpio_get_multiple(), and adm1266_gpio_dbg_show() so the > GPIO PMBus reads can't land between a PAGE write and the paged > read pmbus_core does in another thread. > > Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai> > --- All these make sense to me. Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
© 2016 - 2026 Red Hat, Inc.