linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains()
@ 2020-09-23  8:44 Dan Carpenter
  2020-09-23  9:10 ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2020-09-23  8:44 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Magnus Damm, Simon Horman, linux-renesas-soc, linux-kernel,
	kernel-janitors

This code needs to call iounmap() on the error paths.

Fixes: 2ed29e15e4b2 ("ARM: shmobile: R-Mobile: Move pm-rmobile to drivers/soc/renesas/")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/soc/renesas/rmobile-sysc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/soc/renesas/rmobile-sysc.c b/drivers/soc/renesas/rmobile-sysc.c
index 54b616ad4a62..d8e6dc650939 100644
--- a/drivers/soc/renesas/rmobile-sysc.c
+++ b/drivers/soc/renesas/rmobile-sysc.c
@@ -328,6 +328,7 @@ static int __init rmobile_init_pm_domains(void)
 		pmd = of_get_child_by_name(np, "pm-domains");
 		if (!pmd) {
 			pr_warn("%pOF lacks pm-domains node\n", np);
+			iounmap(base);
 			continue;
 		}
 
@@ -341,6 +342,7 @@ static int __init rmobile_init_pm_domains(void)
 		of_node_put(pmd);
 		if (ret) {
 			of_node_put(np);
+			iounmap(base);
 			break;
 		}
 	}
-- 
2.28.0


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

* Re: [PATCH] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains()
  2020-09-23  8:44 [PATCH] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains() Dan Carpenter
@ 2020-09-23  9:10 ` Geert Uytterhoeven
  2020-09-23 10:28   ` Dan Carpenter
  2020-09-23 11:31   ` [PATCH v2] " Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2020-09-23  9:10 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Magnus Damm, Simon Horman, Linux-Renesas,
	Linux Kernel Mailing List, kernel-janitors

Hi Dan,

On Wed, Sep 23, 2020 at 10:47 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> This code needs to call iounmap() on the error paths.

Thanks for your patch!

> Fixes: 2ed29e15e4b2 ("ARM: shmobile: R-Mobile: Move pm-rmobile to drivers/soc/renesas/")

This is not the commit that introduced the issue.

Fixes: 2173fc7cb681c38b ("ARM: shmobile: R-Mobile: Add DT support for
PM domains")

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

> --- a/drivers/soc/renesas/rmobile-sysc.c
> +++ b/drivers/soc/renesas/rmobile-sysc.c
> @@ -328,6 +328,7 @@ static int __init rmobile_init_pm_domains(void)
>                 pmd = of_get_child_by_name(np, "pm-domains");
>                 if (!pmd) {
>                         pr_warn("%pOF lacks pm-domains node\n", np);
> +                       iounmap(base);

This one I can agree with, although that case is a bug in the DTS.

>                         continue;
>                 }
>
> @@ -341,6 +342,7 @@ static int __init rmobile_init_pm_domains(void)
>                 of_node_put(pmd);
>                 if (ret) {
>                         of_node_put(np);
> +                       iounmap(base);

This one I cannot: in the (unlikely, only if OOM) case
rmobile_add_pm_domains() returns an error, one or more PM subdomains may
have been registered already.  Hence if you call iounmap() here, the
code will try to access unmapped registers later, leading to a crash.

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] 5+ messages in thread

* Re: [PATCH] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains()
  2020-09-23  9:10 ` Geert Uytterhoeven
@ 2020-09-23 10:28   ` Dan Carpenter
  2020-09-23 11:31   ` [PATCH v2] " Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2020-09-23 10:28 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Magnus Damm, Simon Horman, Linux-Renesas,
	Linux Kernel Mailing List, kernel-janitors

On Wed, Sep 23, 2020 at 11:10:17AM +0200, Geert Uytterhoeven wrote:
> Hi Dan,
> 
> On Wed, Sep 23, 2020 at 10:47 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > This code needs to call iounmap() on the error paths.
> 
> Thanks for your patch!
> 
> > Fixes: 2ed29e15e4b2 ("ARM: shmobile: R-Mobile: Move pm-rmobile to drivers/soc/renesas/")
> 
> This is not the commit that introduced the issue.

Duh...  I don't know what I was thinking there.

> 
> Fixes: 2173fc7cb681c38b ("ARM: shmobile: R-Mobile: Add DT support for
> PM domains")
> 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> > --- a/drivers/soc/renesas/rmobile-sysc.c
> > +++ b/drivers/soc/renesas/rmobile-sysc.c
> > @@ -328,6 +328,7 @@ static int __init rmobile_init_pm_domains(void)
> >                 pmd = of_get_child_by_name(np, "pm-domains");
> >                 if (!pmd) {
> >                         pr_warn("%pOF lacks pm-domains node\n", np);
> > +                       iounmap(base);
> 
> This one I can agree with, although that case is a bug in the DTS.
> 
> >                         continue;
> >                 }
> >
> > @@ -341,6 +342,7 @@ static int __init rmobile_init_pm_domains(void)
> >                 of_node_put(pmd);
> >                 if (ret) {
> >                         of_node_put(np);
> > +                       iounmap(base);
> 
> This one I cannot: in the (unlikely, only if OOM) case
> rmobile_add_pm_domains() returns an error, one or more PM subdomains may
> have been registered already.  Hence if you call iounmap() here, the
> code will try to access unmapped registers later, leading to a crash.
> 

It's actually impossible for this rmobile_add_pm_domains() to fail on
current kernels because small allocations never fail...

I'll send a v2.  This is for a new static checker test that I added to
Smatch so I'm just sending a few of these out every day to collect
feedback for now.  So thanks for reviewing this, it's very helpful.

regards,
dan carpenter


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

* [PATCH v2] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains()
  2020-09-23  9:10 ` Geert Uytterhoeven
  2020-09-23 10:28   ` Dan Carpenter
@ 2020-09-23 11:31   ` Dan Carpenter
  2020-09-24  7:35     ` Geert Uytterhoeven
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2020-09-23 11:31 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Magnus Damm, Simon Horman, linux-renesas-soc, linux-kernel,
	kernel-janitors

This code needs to call iounmap() on one error path.

Fixes: 2173fc7cb681 ("ARM: shmobile: R-Mobile: Add DT support for PM domains")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2:  The v1 patch potentially led to a use after free.

 drivers/soc/renesas/rmobile-sysc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/soc/renesas/rmobile-sysc.c b/drivers/soc/renesas/rmobile-sysc.c
index 54b616ad4a62..beb1c7211c3d 100644
--- a/drivers/soc/renesas/rmobile-sysc.c
+++ b/drivers/soc/renesas/rmobile-sysc.c
@@ -327,6 +327,7 @@ static int __init rmobile_init_pm_domains(void)
 
 		pmd = of_get_child_by_name(np, "pm-domains");
 		if (!pmd) {
+			iounmap(base);
 			pr_warn("%pOF lacks pm-domains node\n", np);
 			continue;
 		}
-- 
2.28.0


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

* Re: [PATCH v2] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains()
  2020-09-23 11:31   ` [PATCH v2] " Dan Carpenter
@ 2020-09-24  7:35     ` Geert Uytterhoeven
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2020-09-24  7:35 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Magnus Damm, Simon Horman, Linux-Renesas,
	Linux Kernel Mailing List, kernel-janitors

On Wed, Sep 23, 2020 at 1:31 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> This code needs to call iounmap() on one error path.
>
> Fixes: 2173fc7cb681 ("ARM: shmobile: R-Mobile: Add DT support for PM domains")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2:  The v1 patch potentially led to a use after free.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
i.e. will queue in renesas-devel for v5.11.

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] 5+ messages in thread

end of thread, other threads:[~2020-09-24  7:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23  8:44 [PATCH] soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains() Dan Carpenter
2020-09-23  9:10 ` Geert Uytterhoeven
2020-09-23 10:28   ` Dan Carpenter
2020-09-23 11:31   ` [PATCH v2] " Dan Carpenter
2020-09-24  7:35     ` Geert Uytterhoeven

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