From: sashiko-bot@kernel.org
To: "Abdurrahman Hussain" <abdurrahman@nexthop.ai>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 5/5] hwmon: (pmbus/adm1266) serialize GPIO PMBus accesses with pmbus_lock
Date: Sun, 17 May 2026 01:39:13 +0000 [thread overview]
Message-ID: <20260517013913.8AF81C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260516-adm1266-gpio-fixes-v2-5-801f13debcb2@nexthop.ai>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Pre-existing Stack and Heap buffer overflows in `adm1266_nvmem_read_blackbox` from untrusted device input.
- [High] Incomplete Fix: NVMEM and debugfs accessors are left unlocked, and probe ordering prevents safely locking them.
- [High] Pre-existing out-of-bounds write and read in `adm1266_pmbus_block_xfer` due to off-by-one buffer size.
--
commit d839d29e2c4f90780c618b15f0a81b58788bc399
Author: Abdurrahman Hussain <abdurrahman@nexthop.ai>
hwmon: (pmbus/adm1266) serialize GPIO PMBus accesses with pmbus_lock
This commit takes pmbus_lock at the top of GPIO accessors via the scope-based
guard() to serialize PMBus accesses and avoid corrupting the device state
machine.
> adm1266_gpio_get(), adm1266_gpio_get_multiple(), and
> adm1266_gpio_dbg_show() all issue PMBus reads against the device but
> none of them take pmbus_lock. The pmbus_core framework holds
> pmbus_lock around its own multi-transaction sequences (notably the
> "set PAGE, then read paged register" pattern used by hwmon
> attributes), so an unlocked GPIO accessor can land between a PAGE
> write and the subsequent paged read in another thread and corrupt
> either side's view of the device state machine.
Are adm1266_nvmem_read() and adm1266_state_read() also vulnerable to this
interleaving race condition? They issue PMBus reads directly against the device
and can be triggered concurrently by userspace via debugfs, so it seems they
might also corrupt the device state machine if left unlocked.
If pmbus_lock is added to the NVMEM path, is the driver's probe sequence safe?
Currently, adm1266_probe() registers the NVMEM device before calling
pmbus_do_probe() which allocates the clientdata. If an early NVMEM read occurs
before pmbus_do_probe() completes, it seems i2c_get_clientdata() would return
NULL, which could cause a panic when dereferencing the lock.
> diff --git a/drivers/hwmon/pmbus/adm1266.c b/drivers/hwmon/pmbus/adm1266.c
> index b91dcf067fa6d..2e9ae03ab64b0 100644
> --- a/drivers/hwmon/pmbus/adm1266.c
> +++ b/drivers/hwmon/pmbus/adm1266.c
[ ... ]
> @@ -235,6 +239,8 @@ static void adm1266_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
> int ret;
> int i;
>
> + guard(pmbus_lock)(data->client);
> +
> for (i = 0; i < ADM1266_GPIO_NR; i++) {
> write_cmd = adm1266_gpio_mapping[i][1];
> ret = adm1266_pmbus_block_xfer(data, ADM1266_GPIO_CONFIG, 1, &write_cmd, read_buf);
Does adm1266_pmbus_block_xfer() write past the end of the data->read_buf array?
The read_buf array in struct adm1266_data is declared as 256 bytes:
u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1] ____cacheline_aligned;
But adm1266_pmbus_block_xfer() initializes the I2C read message with a larger
length:
static int adm1266_pmbus_block_xfer(...)
{
...
{
.addr = client->addr,
.flags = I2C_M_RD | I2C_M_DMA_SAFE,
.buf = data->read_buf,
.len = ADM1266_PMBUS_BLOCK_MAX + 2,
}
};
...
Could this cause i2c_transfer() to write 257 bytes into the 256-byte array?
Additionally, if I2C_CLIENT_PEC is enabled and the device returns a max length
byte of 255, could the PEC validation logic perform an out-of-bounds read at
index 256?
While reviewing this file, I also noticed two other regressions in
adm1266_nvmem_read_blackbox().
First, it passes a local 5-byte array to i2c_smbus_read_block_data():
u8 buf[5];
...
ret = i2c_smbus_read_block_data(client, ADM1266_READ_BLACKBOX_INFO, buf);
Since i2c_smbus_read_block_data() copies up to I2C_SMBUS_BLOCK_MAX (32) bytes
into the destination array based on the length returned by the device, could a
device returning a length greater than 5 overflow the buf stack array?
Second, it reads record_count from the device response:
record_count = buf[3];
Then it uses this in a loop:
for (i = 0; i < record_count; i++) {
...
read_buff += ADM1266_BLACKBOX_SIZE;
}
Since data->dev_mem is allocated with a fixed size of 2048 bytes, and
ADM1266_BLACKBOX_SIZE is 64 bytes, if the device returns a record_count greater
than 32, could this loop write past the end of the data->dev_mem array?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260516-adm1266-gpio-fixes-v2-0-801f13debcb2@nexthop.ai?part=5
next prev parent reply other threads:[~2026-05-17 1:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 23:18 [PATCH v2 0/5] hwmon: (pmbus/adm1266) GPIO accessor fixes Abdurrahman Hussain
2026-05-16 23:18 ` [PATCH v2 1/5] hwmon: (pmbus/adm1266) cap PDIO scan in get_multiple at ADM1266_PDIO_NR Abdurrahman Hussain
2026-05-16 23:38 ` sashiko-bot
2026-05-16 23:18 ` [PATCH v2 2/5] hwmon: (pmbus/adm1266) don't clobber GPIO bits before PDIO read in get_multiple Abdurrahman Hussain
2026-05-16 23:18 ` [PATCH v2 3/5] hwmon: (pmbus/adm1266) reject short block-read responses in the GPIO accessors Abdurrahman Hussain
2026-05-17 0:22 ` sashiko-bot
2026-05-16 23:18 ` [PATCH v2 4/5] hwmon: (pmbus/adm1266) register the gpio_chip after pmbus_do_probe() Abdurrahman Hussain
2026-05-17 1:01 ` sashiko-bot
2026-05-16 23:18 ` [PATCH v2 5/5] hwmon: (pmbus/adm1266) serialize GPIO PMBus accesses with pmbus_lock Abdurrahman Hussain
2026-05-17 1:39 ` sashiko-bot [this message]
2026-05-18 9:08 ` [PATCH v2 0/5] hwmon: (pmbus/adm1266) GPIO accessor fixes Bartosz Golaszewski
2026-05-18 22:08 ` Guenter Roeck
2026-05-19 0:50 ` Abdurrahman Hussain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260517013913.8AF81C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=abdurrahman@nexthop.ai \
--cc=linux-hwmon@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox