| From fc2f6d017569bcd6e08eaf6646136ba37d0039e4 Mon Sep 17 00:00:00 2001 |
| From: Wen Yang <wenyang@linux.alibaba.com> |
| Date: Sun, 24 Nov 2019 22:58:35 +0800 |
| Subject: [PATCH] regulator: fix use after free issue |
| |
| commit 4affd79a125ac91e6a53be843ea3960a8fc00cbb upstream. |
| |
| This is caused by dereferencing 'rdev' after put_device() in |
| the _regulator_get()/_regulator_put() functions. |
| This patch just moves the put_device() down a bit to avoid the |
| issue. |
| |
| Signed-off-by: Wen Yang <wenyang@linux.alibaba.com> |
| Cc: Liam Girdwood <lgirdwood@gmail.com> |
| Cc: Mark Brown <broonie@kernel.org> |
| Cc: linux-kernel@vger.kernel.org |
| Link: https://lore.kernel.org/r/20191124145835.25999-1-wenyang@linux.alibaba.com |
| Signed-off-by: Mark Brown <broonie@kernel.org> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c |
| index 40abd7746f51..ca9c7b0b17b1 100644 |
| --- a/drivers/regulator/core.c |
| +++ b/drivers/regulator/core.c |
| @@ -1934,8 +1934,8 @@ struct regulator *_regulator_get(struct device *dev, const char *id, |
| regulator = create_regulator(rdev, dev, id); |
| if (regulator == NULL) { |
| regulator = ERR_PTR(-ENOMEM); |
| - put_device(&rdev->dev); |
| module_put(rdev->owner); |
| + put_device(&rdev->dev); |
| return regulator; |
| } |
| |
| @@ -2056,13 +2056,13 @@ static void _regulator_put(struct regulator *regulator) |
| |
| rdev->open_count--; |
| rdev->exclusive = 0; |
| - put_device(&rdev->dev); |
| regulator_unlock(rdev); |
| |
| kfree_const(regulator->supply_name); |
| kfree(regulator); |
| |
| module_put(rdev->owner); |
| + put_device(&rdev->dev); |
| } |
| |
| /** |
| -- |
| 2.7.4 |
| |