All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive()
@ 2020-08-31 20:43 Dmitry Osipenko
  2020-09-01 14:50 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Osipenko @ 2020-08-31 20:43 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown; +Cc: linux-kernel

The recent commit 7d8196641ee1 ("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: f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/regulator/core.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5eda1927a4aa..8796c9a24b28 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -236,8 +236,8 @@ static bool regulator_supply_is_couple(struct regulator_dev *rdev)
 static void regulator_unlock_recursive(struct regulator_dev *rdev,
 				       unsigned int n_coupled)
 {
-	struct regulator_dev *c_rdev;
-	int i;
+	struct regulator_dev *c_rdev, *supply_rdev;
+	int i, supply_n_coupled;
 
 	for (i = n_coupled; i > 0; i--) {
 		c_rdev = rdev->coupling_desc.coupled_rdevs[i - 1];
@@ -245,10 +245,13 @@ static void regulator_unlock_recursive(struct regulator_dev *rdev,
 		if (!c_rdev)
 			continue;
 
-		if (c_rdev->supply && !regulator_supply_is_couple(c_rdev))
-			regulator_unlock_recursive(
-					c_rdev->supply->rdev,
-					c_rdev->coupling_desc.n_coupled);
+		if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) {
+			supply_rdev = c_rdev->supply->rdev;
+			supply_n_coupled = supply_rdev->coupling_desc.n_coupled;
+
+			regulator_unlock_recursive(supply_rdev,
+						   supply_n_coupled);
+		}
 
 		regulator_unlock(c_rdev);
 	}
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive()
  2020-08-31 20:43 [PATCH v1] regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive() Dmitry Osipenko
@ 2020-09-01 14:50 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2020-09-01 14:50 UTC (permalink / raw)
  To: Dmitry Osipenko, Liam Girdwood; +Cc: linux-kernel

On Mon, 31 Aug 2020 23:43:35 +0300, Dmitry Osipenko wrote:
> The recent commit 7d8196641ee1 ("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.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive()
      commit: 0a7416f94707c60b9f66b01c0a505b7e41375f3a

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-01 14:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 20:43 [PATCH v1] regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive() Dmitry Osipenko
2020-09-01 14:50 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.