Skip to content

Commit

Permalink
regulator: pfuze100: Fix the global-out-of-bounds access in pfuze100_…
Browse files Browse the repository at this point in the history
…regulator_probe()

[ Upstream commit 78e1e86 ]

The pfuze_chip::regulator_descs is an array of size
PFUZE100_MAX_REGULATOR, the pfuze_chip::pfuze_regulators
is the pointer to the real regulators of a specific device.
The number of real regulator is supposed to be less than
the PFUZE100_MAX_REGULATOR, so we should use the size of
'regulator_num * sizeof(struct pfuze_regulator)' in memcpy().
This fixes the out of bounds access bug reported by KASAN.

Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
Link: https://lore.kernel.org/r/20220825111922.1368055-1-xiaolei.wang@windriver.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Xiaolei Wang authored and gregkh committed Sep 23, 2022
1 parent 80c7be2 commit f08a320
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/regulator/pfuze100-regulator.c
Expand Up @@ -763,7 +763,7 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
((pfuze_chip->chip_id == PFUZE3000) ? "3000" : "3001"))));

memcpy(pfuze_chip->regulator_descs, pfuze_chip->pfuze_regulators,
sizeof(pfuze_chip->regulator_descs));
regulator_num * sizeof(struct pfuze_regulator));

ret = pfuze_parse_regulators_dt(pfuze_chip);
if (ret)
Expand Down

0 comments on commit f08a320

Please sign in to comment.