linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] clk: samsung: Fix kfree() of const memory on setting driver_override
@ 2019-02-21 11:45 Krzysztof Kozlowski
  2019-02-21 11:45 ` [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure Krzysztof Kozlowski
  2019-02-21 11:45 ` [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
  0 siblings, 2 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2019-02-21 11:45 UTC (permalink / raw)
  To: Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, Krzysztof Kozlowski, linux-samsung-soc,
	linux-clk, linux-arm-kernel, linux-kernel

Hi,

Changes since v1:
1. Split clock-related fixes out of bigger platform patchset.
2. Remove usage of driver_override.

Best regards,
Krzysztof


Krzysztof Kozlowski (2):
  clk: samsung: exynos5: Fix possible NULL pointer exception on
    platform_device_alloc() failure
  clk: samsung: exynos5: Fix kfree() of const memory on setting
    driver_override

 drivers/clk/samsung/clk-exynos5-subcmu.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

-- 
2.7.4


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

* [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure
  2019-02-21 11:45 [PATCH v2 0/2] clk: samsung: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
@ 2019-02-21 11:45 ` Krzysztof Kozlowski
  2019-02-21 15:43   ` Geert Uytterhoeven
  2019-02-21 21:33   ` Stephen Boyd
  2019-02-21 11:45 ` [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
  1 sibling, 2 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2019-02-21 11:45 UTC (permalink / raw)
  To: Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, Krzysztof Kozlowski, linux-samsung-soc,
	linux-clk, linux-arm-kernel, linux-kernel
  Cc: stable

During initialization of subdevices if platform_device_alloc() failed,
returned NULL pointer will be later dereferenced.  Add proper error
paths to exynos5_clk_register_subcmu().  The return value of this
function is still ignored because at this stage of init there is nothing
we can do.

Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/clk/samsung/clk-exynos5-subcmu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/samsung/clk-exynos5-subcmu.c b/drivers/clk/samsung/clk-exynos5-subcmu.c
index 93306283d764..d07ef26bd052 100644
--- a/drivers/clk/samsung/clk-exynos5-subcmu.c
+++ b/drivers/clk/samsung/clk-exynos5-subcmu.c
@@ -136,15 +136,21 @@ static int __init exynos5_clk_register_subcmu(struct device *parent,
 {
 	struct of_phandle_args genpdspec = { .np = pd_node };
 	struct platform_device *pdev;
+	int ret;
 
 	pdev = platform_device_alloc(info->pd_name, -1);
+	if (!pdev)
+		return -ENOMEM;
+
 	pdev->dev.parent = parent;
 	pdev->driver_override = "exynos5-subcmu";
 	platform_set_drvdata(pdev, (void *)info);
 	of_genpd_add_device(&genpdspec, &pdev->dev);
-	platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret)
+		platform_device_put(pdev);
 
-	return 0;
+	return ret;
 }
 
 static int __init exynos5_clk_probe(struct platform_device *pdev)
-- 
2.7.4


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

* [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override
  2019-02-21 11:45 [PATCH v2 0/2] clk: samsung: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
  2019-02-21 11:45 ` [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure Krzysztof Kozlowski
@ 2019-02-21 11:45 ` Krzysztof Kozlowski
  2019-02-21 15:44   ` Geert Uytterhoeven
  2019-02-21 21:33   ` Stephen Boyd
  1 sibling, 2 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2019-02-21 11:45 UTC (permalink / raw)
  To: Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, Krzysztof Kozlowski, linux-samsung-soc,
	linux-clk, linux-arm-kernel, linux-kernel
  Cc: stable

Platform driver driver_override field should not be initialized from
const memory because the core later kfree() it.  If driver_override is
manually set later through sysfs, kfree() of old value leads to:

    $ echo "new_value" > /sys/bus/platform/drivers/.../driver_override

    kernel BUG at ../mm/slub.c:3960!
    Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM
    ...
    (kfree) from [<c058e8c0>] (platform_set_driver_override+0x84/0xac)
    (platform_set_driver_override) from [<c058e908>] (driver_override_store+0x20/0x34)
    (driver_override_store) from [<c031f778>] (kernfs_fop_write+0x100/0x1dc)
    (kernfs_fop_write) from [<c0296de8>] (__vfs_write+0x2c/0x17c)
    (__vfs_write) from [<c02970c4>] (vfs_write+0xa4/0x188)
    (vfs_write) from [<c02972e8>] (ksys_write+0x4c/0xac)
    (ksys_write) from [<c0101000>] (ret_fast_syscall+0x0/0x28)

The clk-exynos5-subcmu driver uses override only for the purpose of
creating meaningful names for children devices (matching names of power
domains, e.g. DISP, MFC).  The driver_override was not developed for
this purpose so just switch to default names of devices to fix the
issue.

Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/clk/samsung/clk-exynos5-subcmu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/clk/samsung/clk-exynos5-subcmu.c b/drivers/clk/samsung/clk-exynos5-subcmu.c
index d07ef26bd052..8ae44b5db4c2 100644
--- a/drivers/clk/samsung/clk-exynos5-subcmu.c
+++ b/drivers/clk/samsung/clk-exynos5-subcmu.c
@@ -138,12 +138,11 @@ static int __init exynos5_clk_register_subcmu(struct device *parent,
 	struct platform_device *pdev;
 	int ret;
 
-	pdev = platform_device_alloc(info->pd_name, -1);
+	pdev = platform_device_alloc("exynos5-subcmu", PLATFORM_DEVID_AUTO);
 	if (!pdev)
 		return -ENOMEM;
 
 	pdev->dev.parent = parent;
-	pdev->driver_override = "exynos5-subcmu";
 	platform_set_drvdata(pdev, (void *)info);
 	of_genpd_add_device(&genpdspec, &pdev->dev);
 	ret = platform_device_add(pdev);
-- 
2.7.4


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

* Re: [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure
  2019-02-21 11:45 ` [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure Krzysztof Kozlowski
@ 2019-02-21 15:43   ` Geert Uytterhoeven
  2019-02-21 21:33   ` Stephen Boyd
  1 sibling, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-02-21 15:43 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, linux-samsung-soc, linux-clk,
	Linux ARM, Linux Kernel Mailing List, stable

On Thu, Feb 21, 2019 at 12:47 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> During initialization of subdevices if platform_device_alloc() failed,
> returned NULL pointer will be later dereferenced.  Add proper error
> paths to exynos5_clk_register_subcmu().  The return value of this
> function is still ignored because at this stage of init there is nothing
> we can do.
>
> Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override
  2019-02-21 11:45 ` [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
@ 2019-02-21 15:44   ` Geert Uytterhoeven
  2019-02-21 21:33   ` Stephen Boyd
  1 sibling, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-02-21 15:44 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sylwester Nawrocki, Tomasz Figa, Chanwoo Choi, Michael Turquette,
	Stephen Boyd, Kukjin Kim, linux-samsung-soc, linux-clk,
	Linux ARM, Linux Kernel Mailing List, stable

On Thu, Feb 21, 2019 at 12:46 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
> Platform driver driver_override field should not be initialized from
> const memory because the core later kfree() it.  If driver_override is
> manually set later through sysfs, kfree() of old value leads to:
>
>     $ echo "new_value" > /sys/bus/platform/drivers/.../driver_override
>
>     kernel BUG at ../mm/slub.c:3960!
>     Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM
>     ...
>     (kfree) from [<c058e8c0>] (platform_set_driver_override+0x84/0xac)
>     (platform_set_driver_override) from [<c058e908>] (driver_override_store+0x20/0x34)
>     (driver_override_store) from [<c031f778>] (kernfs_fop_write+0x100/0x1dc)
>     (kernfs_fop_write) from [<c0296de8>] (__vfs_write+0x2c/0x17c)
>     (__vfs_write) from [<c02970c4>] (vfs_write+0xa4/0x188)
>     (vfs_write) from [<c02972e8>] (ksys_write+0x4c/0xac)
>     (ksys_write) from [<c0101000>] (ret_fast_syscall+0x0/0x28)
>
> The clk-exynos5-subcmu driver uses override only for the purpose of
> creating meaningful names for children devices (matching names of power
> domains, e.g. DISP, MFC).  The driver_override was not developed for
> this purpose so just switch to default names of devices to fix the
> issue.
>
> Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure
  2019-02-21 11:45 ` [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure Krzysztof Kozlowski
  2019-02-21 15:43   ` Geert Uytterhoeven
@ 2019-02-21 21:33   ` Stephen Boyd
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2019-02-21 21:33 UTC (permalink / raw)
  To: Chanwoo Choi, Krzysztof Kozlowski, Kukjin Kim, Michael Turquette,
	Sylwester Nawrocki, Tomasz Figa, linux-arm-kernel, linux-clk,
	linux-kernel, linux-samsung-soc
  Cc: stable

Quoting Krzysztof Kozlowski (2019-02-21 03:45:51)
> During initialization of subdevices if platform_device_alloc() failed,
> returned NULL pointer will be later dereferenced.  Add proper error
> paths to exynos5_clk_register_subcmu().  The return value of this
> function is still ignored because at this stage of init there is nothing
> we can do.
> 
> Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---

Applied to clk-next


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

* Re: [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override
  2019-02-21 11:45 ` [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
  2019-02-21 15:44   ` Geert Uytterhoeven
@ 2019-02-21 21:33   ` Stephen Boyd
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2019-02-21 21:33 UTC (permalink / raw)
  To: Chanwoo Choi, Krzysztof Kozlowski, Kukjin Kim, Michael Turquette,
	Sylwester Nawrocki, Tomasz Figa, linux-arm-kernel, linux-clk,
	linux-kernel, linux-samsung-soc
  Cc: stable

Quoting Krzysztof Kozlowski (2019-02-21 03:45:52)
> Platform driver driver_override field should not be initialized from
> const memory because the core later kfree() it.  If driver_override is
> manually set later through sysfs, kfree() of old value leads to:
> 
>     $ echo "new_value" > /sys/bus/platform/drivers/.../driver_override
> 
>     kernel BUG at ../mm/slub.c:3960!
>     Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM
>     ...
>     (kfree) from [<c058e8c0>] (platform_set_driver_override+0x84/0xac)
>     (platform_set_driver_override) from [<c058e908>] (driver_override_store+0x20/0x34)
>     (driver_override_store) from [<c031f778>] (kernfs_fop_write+0x100/0x1dc)
>     (kernfs_fop_write) from [<c0296de8>] (__vfs_write+0x2c/0x17c)
>     (__vfs_write) from [<c02970c4>] (vfs_write+0xa4/0x188)
>     (vfs_write) from [<c02972e8>] (ksys_write+0x4c/0xac)
>     (ksys_write) from [<c0101000>] (ret_fast_syscall+0x0/0x28)
> 
> The clk-exynos5-subcmu driver uses override only for the purpose of
> creating meaningful names for children devices (matching names of power
> domains, e.g. DISP, MFC).  The driver_override was not developed for
> this purpose so just switch to default names of devices to fix the
> issue.
> 
> Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---

Applied to clk-next


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

end of thread, other threads:[~2019-02-21 21:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 11:45 [PATCH v2 0/2] clk: samsung: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
2019-02-21 11:45 ` [PATCH v2 1/2] clk: samsung: exynos5: Fix possible NULL pointer exception on platform_device_alloc() failure Krzysztof Kozlowski
2019-02-21 15:43   ` Geert Uytterhoeven
2019-02-21 21:33   ` Stephen Boyd
2019-02-21 11:45 ` [PATCH v2 2/2] clk: samsung: exynos5: Fix kfree() of const memory on setting driver_override Krzysztof Kozlowski
2019-02-21 15:44   ` Geert Uytterhoeven
2019-02-21 21:33   ` Stephen Boyd

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).