Skip to content

Commit 0a7416f

Browse files
digetxbroonie
authored andcommitted
regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive()
The recent commit 7d81966 ("regulator: Remove pointer table overallocation") changed the size of coupled_rdevs and now KASAN is able to detect slab-out-of-bounds problem in regulator_unlock_recursive(), which is a legit problem caused by a typo in the code. The recursive unlock function uses n_coupled value of a parent regulator for unlocking supply regulator, while supply's n_coupled should be used. In practice problem may only affect platforms that use coupled regulators. Cc: stable@vger.kernel.org # 5.0+ Fixes: f8702f9 ("regulator: core: Use ww_mutex for regulators locking") Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Link: https://lore.kernel.org/r/20200831204335.19489-1-digetx@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 3bec5b6 commit 0a7416f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/regulator/core.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,22 @@ static bool regulator_supply_is_couple(struct regulator_dev *rdev)
236236
static void regulator_unlock_recursive(struct regulator_dev *rdev,
237237
unsigned int n_coupled)
238238
{
239-
struct regulator_dev *c_rdev;
240-
int i;
239+
struct regulator_dev *c_rdev, *supply_rdev;
240+
int i, supply_n_coupled;
241241

242242
for (i = n_coupled; i > 0; i--) {
243243
c_rdev = rdev->coupling_desc.coupled_rdevs[i - 1];
244244

245245
if (!c_rdev)
246246
continue;
247247

248-
if (c_rdev->supply && !regulator_supply_is_couple(c_rdev))
249-
regulator_unlock_recursive(
250-
c_rdev->supply->rdev,
251-
c_rdev->coupling_desc.n_coupled);
248+
if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) {
249+
supply_rdev = c_rdev->supply->rdev;
250+
supply_n_coupled = supply_rdev->coupling_desc.n_coupled;
251+
252+
regulator_unlock_recursive(supply_rdev,
253+
supply_n_coupled);
254+
}
252255

253256
regulator_unlock(c_rdev);
254257
}

0 commit comments

Comments
 (0)