linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/pseries: Add null property check to pseries_discover_pic()
@ 2016-04-28  5:53 Suraj Jitindar Singh
  2016-05-02  2:30 ` Chris Smart
  2016-05-04 22:40 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Suraj Jitindar Singh @ 2016-04-28  5:53 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: benh, paulus, mpe, Suraj Jitindar Singh

The return value of of_get_property() isn't checked before it is passed
to the strstr() function, if it happens that the return value is null
then this will result in a null pointer being dereferenced.

Add a check to see if the return value of of_get_property() is null and
if it is continue straight on to the next node.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
---
 arch/powerpc/platforms/pseries/setup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 6e944fc..fa73494 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -235,6 +235,8 @@ static void __init pseries_discover_pic(void)
 
 	for_each_node_by_name(np, "interrupt-controller") {
 		typep = of_get_property(np, "compatible", NULL);
+		if (!typep)
+			continue;
 		if (strstr(typep, "open-pic")) {
 			pSeries_mpic_node = of_node_get(np);
 			ppc_md.init_IRQ       = pseries_mpic_init_IRQ;
-- 
2.5.0

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

* Re: [PATCH] powerpc/pseries: Add null property check to pseries_discover_pic()
  2016-04-28  5:53 [PATCH] powerpc/pseries: Add null property check to pseries_discover_pic() Suraj Jitindar Singh
@ 2016-05-02  2:30 ` Chris Smart
  2016-05-04 22:40 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Smart @ 2016-05-02  2:30 UTC (permalink / raw)
  To: linuxppc-dev

On Thu, Apr 28, 2016 at 03:53:45PM +1000, Suraj Jitindar Singh wrote:
>The return value of of_get_property() isn't checked before it is passed
>to the strstr() function, if it happens that the return value is null
>then this will result in a null pointer being dereferenced.
>
>Add a check to see if the return value of of_get_property() is null and
>if it is continue straight on to the next node.
>

Hi Suraj,

Presumably machines have been shipping with a device tree that contains
"compatible" in the interrupt controller section and so we just happen
to have never hit this. Good thing to check.

Confirming that strstr calls strlen on the first argument, which would
dereference a null pointer.

Reviewed-by: Chris Smart <chris@distroguy.com>

>Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
>---
> arch/powerpc/platforms/pseries/setup.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
>index 6e944fc..fa73494 100644
>--- a/arch/powerpc/platforms/pseries/setup.c
>+++ b/arch/powerpc/platforms/pseries/setup.c
>@@ -235,6 +235,8 @@ static void __init pseries_discover_pic(void)
>
> 	for_each_node_by_name(np, "interrupt-controller") {
> 		typep = of_get_property(np, "compatible", NULL);
>+		if (!typep)
>+			continue;
> 		if (strstr(typep, "open-pic")) {
> 			pSeries_mpic_node = of_node_get(np);
> 			ppc_md.init_IRQ       = pseries_mpic_init_IRQ;
>-- 
>2.5.0
>
>_______________________________________________
>Linuxppc-dev mailing list
>Linuxppc-dev@lists.ozlabs.org
>https://lists.ozlabs.org/listinfo/linuxppc-dev

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

* Re: powerpc/pseries: Add null property check to pseries_discover_pic()
  2016-04-28  5:53 [PATCH] powerpc/pseries: Add null property check to pseries_discover_pic() Suraj Jitindar Singh
  2016-05-02  2:30 ` Chris Smart
@ 2016-05-04 22:40 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2016-05-04 22:40 UTC (permalink / raw)
  To: Suraj Jitindar Singh, linuxppc-dev; +Cc: paulus, Suraj Jitindar Singh

On Thu, 2016-28-04 at 05:53:45 UTC, Suraj Jitindar Singh wrote:
> The return value of of_get_property() isn't checked before it is passed
> to the strstr() function, if it happens that the return value is null
> then this will result in a null pointer being dereferenced.
> 
> Add a check to see if the return value of of_get_property() is null and
> if it is continue straight on to the next node.
> 
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
> Reviewed-by: Chris Smart <chris@distroguy.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/9ed3f7bcab00c9477e382e6589

cheers

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

end of thread, other threads:[~2016-05-04 22:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-28  5:53 [PATCH] powerpc/pseries: Add null property check to pseries_discover_pic() Suraj Jitindar Singh
2016-05-02  2:30 ` Chris Smart
2016-05-04 22:40 ` Michael Ellerman

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