Message ID | 1666283513-17005-1-git-send-email-u0084500@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mfd: mt6370: Add the overbound check to prevent the null pointer | expand |
On Thu, Oct 20, 2022 at 7:31 PM cy_huang <u0084500@gmail.com> wrote: > > From: ChiYuan Huang <cy_huang@richtek.com> > > This potential risk could happen at regmap_raw_read or > regmap_raw_write when accessing the over-bound register address. Functions are referred to as func(). > Below's the issue reproduced log to access over-bound register with > regmap_raw_read function. Ditto. > [ 41.301385] Hardware name: Raspberry Pi 4 Model B Rev 1.2 (DT) > [ 41.307296] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) Please, read Submitting Patches, and trim your commit message accordingly.
diff --git a/drivers/mfd/mt6370.c b/drivers/mfd/mt6370.c index cf19cce..acbf960 100644 --- a/drivers/mfd/mt6370.c +++ b/drivers/mfd/mt6370.c @@ -190,6 +190,9 @@ static int mt6370_regmap_read(void *context, const void *reg_buf, bank_idx = u8_buf[0]; bank_addr = u8_buf[1]; + if (bank_idx >= MT6370_MAX_I2C) + return -EINVAL; + ret = i2c_smbus_read_i2c_block_data(info->i2c[bank_idx], bank_addr, val_size, val_buf); if (ret < 0) @@ -211,6 +214,9 @@ static int mt6370_regmap_write(void *context, const void *data, size_t count) bank_idx = u8_buf[0]; bank_addr = u8_buf[1]; + if (bank_idx >= MT6370_MAX_I2C) + return -EINVAL; + return i2c_smbus_write_i2c_block_data(info->i2c[bank_idx], bank_addr, len, data + MT6370_MAX_ADDRLEN); }