* [PATCH v2] mfd: mt6360: add bound check in regmap read/write function
@ 2022-09-29 2:00 cy_huang
2022-10-20 7:46 ` ChiYuan Huang
2022-10-31 13:52 ` Lee Jones
0 siblings, 2 replies; 3+ messages in thread
From: cy_huang @ 2022-09-29 2:00 UTC (permalink / raw)
To: lee
Cc: matthias.bgg, gene_chen, linux-arm-kernel, linux-mediatek,
linux-kernel, ChiYuan Huang, stable
From: ChiYuan Huang <cy_huang@richtek.com>
Fix the potential risk for null pointer if bank index is over the maximum.
Refer to the discussion list for the experiment result on mt6370.
https://lore.kernel.org/all/20220914013345.GA5802@cyhuang-hp-elitebook-840-g3.rt/
If not to check the bound, there is the same issue on mt6360.
Fixes: 3b0850440a06c (mfd: mt6360: Merge different sub-devices I2C read/write)
Cc: stable@vger.kernel.org
Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
---
Since v2:
- Assign i2c bank variable after bank index is already checked.
---
drivers/mfd/mt6360-core.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c
index 6eaa677..d3b32eb 100644
--- a/drivers/mfd/mt6360-core.c
+++ b/drivers/mfd/mt6360-core.c
@@ -402,7 +402,7 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
struct mt6360_ddata *ddata = context;
u8 bank = *(u8 *)reg;
u8 reg_addr = *(u8 *)(reg + 1);
- struct i2c_client *i2c = ddata->i2c[bank];
+ struct i2c_client *i2c;
bool crc_needed = false;
u8 *buf;
int buf_len = MT6360_ALLOC_READ_SIZE(val_size);
@@ -410,6 +410,11 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
u8 crc;
int ret;
+ if (bank >= MT6360_SLAVE_MAX)
+ return -EINVAL;
+
+ i2c = ddata->i2c[bank];
+
if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) {
crc_needed = true;
ret = mt6360_xlate_pmicldo_addr(®_addr, val_size);
@@ -453,13 +458,18 @@ static int mt6360_regmap_write(void *context, const void *val, size_t val_size)
struct mt6360_ddata *ddata = context;
u8 bank = *(u8 *)val;
u8 reg_addr = *(u8 *)(val + 1);
- struct i2c_client *i2c = ddata->i2c[bank];
+ struct i2c_client *i2c;
bool crc_needed = false;
u8 *buf;
int buf_len = MT6360_ALLOC_WRITE_SIZE(val_size);
int write_size = val_size - MT6360_REGMAP_REG_BYTE_SIZE;
int ret;
+ if (bank >= MT6360_SLAVE_MAX)
+ return -EINVAL;
+
+ i2c = ddata->i2c[bank];
+
if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) {
crc_needed = true;
ret = mt6360_xlate_pmicldo_addr(®_addr, val_size - MT6360_REGMAP_REG_BYTE_SIZE);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mfd: mt6360: add bound check in regmap read/write function
2022-09-29 2:00 [PATCH v2] mfd: mt6360: add bound check in regmap read/write function cy_huang
@ 2022-10-20 7:46 ` ChiYuan Huang
2022-10-31 13:52 ` Lee Jones
1 sibling, 0 replies; 3+ messages in thread
From: ChiYuan Huang @ 2022-10-20 7:46 UTC (permalink / raw)
To: lee
Cc: matthias.bgg, gene_chen, linux-arm-kernel, linux-mediatek,
linux-kernel, ChiYuan Huang, stable
Hi,
cy_huang <u0084500@gmail.com> 於 2022年9月29日 週四 上午10:00寫道:
>
> From: ChiYuan Huang <cy_huang@richtek.com>
>
> Fix the potential risk for null pointer if bank index is over the maximum.
>
> Refer to the discussion list for the experiment result on mt6370.
> https://lore.kernel.org/all/20220914013345.GA5802@cyhuang-hp-elitebook-840-g3.rt/
> If not to check the bound, there is the same issue on mt6360.
>
> Fixes: 3b0850440a06c (mfd: mt6360: Merge different sub-devices I2C read/write)
> Cc: stable@vger.kernel.org
> Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
> ---
> Since v2:
> - Assign i2c bank variable after bank index is already checked.
>
> ---
> drivers/mfd/mt6360-core.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
Any comment?
> diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c
> index 6eaa677..d3b32eb 100644
> --- a/drivers/mfd/mt6360-core.c
> +++ b/drivers/mfd/mt6360-core.c
> @@ -402,7 +402,7 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
> struct mt6360_ddata *ddata = context;
> u8 bank = *(u8 *)reg;
> u8 reg_addr = *(u8 *)(reg + 1);
> - struct i2c_client *i2c = ddata->i2c[bank];
> + struct i2c_client *i2c;
> bool crc_needed = false;
> u8 *buf;
> int buf_len = MT6360_ALLOC_READ_SIZE(val_size);
> @@ -410,6 +410,11 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
> u8 crc;
> int ret;
>
> + if (bank >= MT6360_SLAVE_MAX)
> + return -EINVAL;
> +
> + i2c = ddata->i2c[bank];
> +
> if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) {
> crc_needed = true;
> ret = mt6360_xlate_pmicldo_addr(®_addr, val_size);
> @@ -453,13 +458,18 @@ static int mt6360_regmap_write(void *context, const void *val, size_t val_size)
> struct mt6360_ddata *ddata = context;
> u8 bank = *(u8 *)val;
> u8 reg_addr = *(u8 *)(val + 1);
> - struct i2c_client *i2c = ddata->i2c[bank];
> + struct i2c_client *i2c;
> bool crc_needed = false;
> u8 *buf;
> int buf_len = MT6360_ALLOC_WRITE_SIZE(val_size);
> int write_size = val_size - MT6360_REGMAP_REG_BYTE_SIZE;
> int ret;
>
> + if (bank >= MT6360_SLAVE_MAX)
> + return -EINVAL;
> +
> + i2c = ddata->i2c[bank];
> +
> if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) {
> crc_needed = true;
> ret = mt6360_xlate_pmicldo_addr(®_addr, val_size - MT6360_REGMAP_REG_BYTE_SIZE);
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mfd: mt6360: add bound check in regmap read/write function
2022-09-29 2:00 [PATCH v2] mfd: mt6360: add bound check in regmap read/write function cy_huang
2022-10-20 7:46 ` ChiYuan Huang
@ 2022-10-31 13:52 ` Lee Jones
1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2022-10-31 13:52 UTC (permalink / raw)
To: cy_huang
Cc: matthias.bgg, gene_chen, linux-arm-kernel, linux-mediatek,
linux-kernel, ChiYuan Huang, stable
On Thu, 29 Sep 2022, cy_huang wrote:
> From: ChiYuan Huang <cy_huang@richtek.com>
>
> Fix the potential risk for null pointer if bank index is over the maximum.
>
> Refer to the discussion list for the experiment result on mt6370.
> https://lore.kernel.org/all/20220914013345.GA5802@cyhuang-hp-elitebook-840-g3.rt/
> If not to check the bound, there is the same issue on mt6360.
>
> Fixes: 3b0850440a06c (mfd: mt6360: Merge different sub-devices I2C read/write)
> Cc: stable@vger.kernel.org
> Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
> ---
> Since v2:
> - Assign i2c bank variable after bank index is already checked.
>
> ---
> drivers/mfd/mt6360-core.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
Applied, thanks.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-31 13:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 2:00 [PATCH v2] mfd: mt6360: add bound check in regmap read/write function cy_huang
2022-10-20 7:46 ` ChiYuan Huang
2022-10-31 13:52 ` Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).