2007-11-26 07:46:52

by Cyrill Gorcunov

[permalink] [raw]
Subject: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

This patch adds checking for NULL value returned to prevent possible
NULL pointer dereference.
Also two unneeded 'return' are removed.

Signed-off-by: Cyrill Gorcunov <[email protected]>
---
Any comments are welcome.


Attachments:
(No filename) (218.00 B)
ppc-celleb-fix-null.diff (2.06 kB)
Download all attachments

2007-11-28 09:01:38

by Kou Ishizaki

[permalink] [raw]
Subject: Re: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

> This patch adds checking for NULL value returned to prevent possible
> NULL pointer dereference.
> Also two unneeded 'return' are removed.
>
> Signed-off-by: Cyrill Gorcunov <[email protected]>

Thanks, I tested your patch and it works.

My original code supposes that the device-tree is provided correctly,
so I omited such checks. (Sorry, it should have been commented.)

Should we check more strictly like your patch?

Best regards,
Kou Ishizaki

2007-11-28 09:49:11

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

On Mon, 2007-11-26 at 10:46 +0300, Cyrill Gorcunov wrote:
> This patch adds checking for NULL value returned to prevent possible
> NULL pointer dereference.
> Also two unneeded 'return' are removed.
>
> Signed-off-by: Cyrill Gorcunov <[email protected]>
> ---
> Any comments are welcome.

I guess it's good to be paranoid, but this is a little verbose:

wi0 = of_get_property(node, "device-id", NULL);
+ if (unlikely((!wi0))) {
+ printk(KERN_ERR "PCI: device-id not found.\n");
+ goto error;
+ }
wi1 = of_get_property(node, "vendor-id", NULL);
+ if (unlikely((!wi1))) {
+ printk(KERN_ERR "PCI: vendor-id not found.\n");
+ goto error;
+ }
wi2 = of_get_property(node, "class-code", NULL);
+ if (unlikely((!wi2))) {
+ printk(KERN_ERR "PCI: class-code not found.\n");
+ goto error;
+ }
wi3 = of_get_property(node, "revision-id", NULL);
+ if (unlikely((!wi3))) {
+ printk(KERN_ERR "PCI: revision-id not found.\n");
+ goto error;
+ }

Perhaps instead:

wi0 = of_get_property(node, "device-id", NULL);
wi1 = of_get_property(node, "vendor-id", NULL);
wi2 = of_get_property(node, "class-code", NULL);
wi3 = of_get_property(node, "revision-id", NULL);

if (!wi0 || !wi1 || !wi2 || !wi3) {
printk(KERN_ERR "PCI: Missing device tree properties.\n");
goto error;
}


cheers

--
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2007-11-28 10:54:00

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

On 11/28/07, Michael Ellerman <[email protected]> wrote:
> On Mon, 2007-11-26 at 10:46 +0300, Cyrill Gorcunov wrote:
> > This patch adds checking for NULL value returned to prevent possible
> > NULL pointer dereference.
> > Also two unneeded 'return' are removed.
> >
> > Signed-off-by: Cyrill Gorcunov <[email protected]>
> > ---
> > Any comments are welcome.
>
> I guess it's good to be paranoid, but this is a little verbose:
>
> wi0 = of_get_property(node, "device-id", NULL);
> + if (unlikely((!wi0))) {
> + printk(KERN_ERR "PCI: device-id not found.\n");
> + goto error;
> + }
> wi1 = of_get_property(node, "vendor-id", NULL);
> + if (unlikely((!wi1))) {
> + printk(KERN_ERR "PCI: vendor-id not found.\n");
> + goto error;
> + }
> wi2 = of_get_property(node, "class-code", NULL);
> + if (unlikely((!wi2))) {
> + printk(KERN_ERR "PCI: class-code not found.\n");
> + goto error;
> + }
> wi3 = of_get_property(node, "revision-id", NULL);
> + if (unlikely((!wi3))) {
> + printk(KERN_ERR "PCI: revision-id not found.\n");
> + goto error;
> + }
>
> Perhaps instead:
>
> wi0 = of_get_property(node, "device-id", NULL);
> wi1 = of_get_property(node, "vendor-id", NULL);
> wi2 = of_get_property(node, "class-code", NULL);
> wi3 = of_get_property(node, "revision-id", NULL);
>
> if (!wi0 || !wi1 || !wi2 || !wi3) {
> printk(KERN_ERR "PCI: Missing device tree properties.\n");
> goto error;
> }

Hi Michael, yes that is much better (actually I was doubt about what form of
which the checking style to use - your form is much compact but mine does
show where *exactly* the problem appeared). So 'case that is the fake driver
your form is preferred ;) Ishizaki, could you use Michael's part then?

>
>
> cheers
>
> --
> Michael Ellerman
> OzLabs, IBM Australia Development Lab
>
> wwweb: http://michael.ellerman.id.au
> phone: +61 2 6212 1183 (tie line 70 21183)
>
> We do not inherit the earth from our ancestors,
> we borrow it from our children. - S.M.A.R.T Person
>
>

Cyrill

2007-11-28 10:59:30

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

On 11/28/07, Cyrill Gorcunov <[email protected]> wrote:
> On 11/28/07, Michael Ellerman <[email protected]> wrote:
> > On Mon, 2007-11-26 at 10:46 +0300, Cyrill Gorcunov wrote:
> > > This patch adds checking for NULL value returned to prevent possible
> > > NULL pointer dereference.
> > > Also two unneeded 'return' are removed.
> > >
> > > Signed-off-by: Cyrill Gorcunov <[email protected]>
> > > ---
> > > Any comments are welcome.
> >
> > I guess it's good to be paranoid, but this is a little verbose:
> >
> > wi0 = of_get_property(node, "device-id", NULL);
> > + if (unlikely((!wi0))) {
> > + printk(KERN_ERR "PCI: device-id not found.\n");
> > + goto error;
> > + }
> > wi1 = of_get_property(node, "vendor-id", NULL);
> > + if (unlikely((!wi1))) {
> > + printk(KERN_ERR "PCI: vendor-id not found.\n");
> > + goto error;
> > + }
> > wi2 = of_get_property(node, "class-code", NULL);
> > + if (unlikely((!wi2))) {
> > + printk(KERN_ERR "PCI: class-code not found.\n");
> > + goto error;
> > + }
> > wi3 = of_get_property(node, "revision-id", NULL);
> > + if (unlikely((!wi3))) {
> > + printk(KERN_ERR "PCI: revision-id not found.\n");
> > + goto error;
> > + }
> >
> > Perhaps instead:
> >
> > wi0 = of_get_property(node, "device-id", NULL);
> > wi1 = of_get_property(node, "vendor-id", NULL);
> > wi2 = of_get_property(node, "class-code", NULL);
> > wi3 = of_get_property(node, "revision-id", NULL);
> >
> > if (!wi0 || !wi1 || !wi2 || !wi3) {
> > printk(KERN_ERR "PCI: Missing device tree properties.\n");
> > goto error;
> > }
>
> Hi Michael, yes that is much better (actually I was doubt about what form of
> which the checking style to use - your form is much compact but mine does
> show where *exactly* the problem appeared). So 'case that is the fake driver
> your form is preferred ;) Ishizaki, could you use Michael's part then?
>
> >
> >
> > cheers
> >
> > --
> > Michael Ellerman
> > OzLabs, IBM Australia Development Lab
> >
> > wwweb: http://michael.ellerman.id.au
> > phone: +61 2 6212 1183 (tie line 70 21183)
> >
> > We do not inherit the earth from our ancestors,
> > we borrow it from our children. - S.M.A.R.T Person
> >
> >
>
> Cyrill
>
Ishizaki I can update the patch if you needed. Should I?

Cyrill

2007-11-29 03:23:19

by Kou Ishizaki

[permalink] [raw]
Subject: Re: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

Cyrill Gorcunov <[email protected]> wrote:
> On 11/28/07, Cyrill Gorcunov <[email protected]> wrote:
> > On 11/28/07, Michael Ellerman <[email protected]> wrote:
> > > On Mon, 2007-11-26 at 10:46 +0300, Cyrill Gorcunov wrote:
> > > > This patch adds checking for NULL value returned to prevent possible
> > > > NULL pointer dereference.
> > > > Also two unneeded 'return' are removed.
> > > >
> > > > Signed-off-by: Cyrill Gorcunov <[email protected]>
> > > > ---
> > > > Any comments are welcome.
> > >
> > > I guess it's good to be paranoid, but this is a little verbose:
> > >
> > > wi0 = of_get_property(node, "device-id", NULL);
> > > + if (unlikely((!wi0))) {
> > > + printk(KERN_ERR "PCI: device-id not found.\n");
> > > + goto error;
> > > + }
> > > wi1 = of_get_property(node, "vendor-id", NULL);
> > > + if (unlikely((!wi1))) {
> > > + printk(KERN_ERR "PCI: vendor-id not found.\n");
> > > + goto error;
> > > + }
> > > wi2 = of_get_property(node, "class-code", NULL);
> > > + if (unlikely((!wi2))) {
> > > + printk(KERN_ERR "PCI: class-code not found.\n");
> > > + goto error;
> > > + }
> > > wi3 = of_get_property(node, "revision-id", NULL);
> > > + if (unlikely((!wi3))) {
> > > + printk(KERN_ERR "PCI: revision-id not found.\n");
> > > + goto error;
> > > + }
> > >
> > > Perhaps instead:
> > >
> > > wi0 = of_get_property(node, "device-id", NULL);
> > > wi1 = of_get_property(node, "vendor-id", NULL);
> > > wi2 = of_get_property(node, "class-code", NULL);
> > > wi3 = of_get_property(node, "revision-id", NULL);
> > >
> > > if (!wi0 || !wi1 || !wi2 || !wi3) {
> > > printk(KERN_ERR "PCI: Missing device tree properties.\n");
> > > goto error;
> > > }
> >
> > Hi Michael, yes that is much better (actually I was doubt about what form of
> > which the checking style to use - your form is much compact but mine does
> > show where *exactly* the problem appeared). So 'case that is the fake driver
> > your form is preferred ;) Ishizaki, could you use Michael's part then?
> >
> > >
> > >
> > > cheers
> > >
> > > --
> > > Michael Ellerman
> > > OzLabs, IBM Australia Development Lab
> > >
> > > wwweb: http://michael.ellerman.id.au
> > > phone: +61 2 6212 1183 (tie line 70 21183)
> > >
> > > We do not inherit the earth from our ancestors,
> > > we borrow it from our children. - S.M.A.R.T Person
> > >
> > >
> >
> > Cyrill
> >
> Ishizaki I can update the patch if you needed. Should I?
>
> Cyrill

There is no problem to use Michael's part, and I also prefer simple
one like this.

Cyrill, would you please update your patch?

Best regards,
Kou Ishizaki

2007-11-29 05:41:27

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [PATCH] PPC: CELLEB - fix potential NULL pointer dereference

On 11/29/07, Ishizaki Kou <[email protected]> wrote:
[...snip...]
>
> There is no problem to use Michael's part, and I also prefer simple
> one like this.
>
> Cyrill, would you please update your patch?
>
> Best regards,
> Kou Ishizaki
>

Please see updated patch enveloped. (Can't do it inline becase I'm on
my work now where I have no Linux machine)

Cyrill


Attachments:
(No filename) (369.00 B)
ppc-celleb-fix-null-v2.diff (1.93 kB)
Download all attachments

2007-11-29 08:15:12

by Kou Ishizaki

[permalink] [raw]
Subject: [PATCH] PPC: CELLEB - fix possible NULL pointer dereference


From: Cyrill Gorcunov <[email protected]>

This patch adds checking for NULL returned value to
prevent possible NULL pointer dereference.

Signed-off-by: Cyrill Gorcunov <[email protected]>
---

Paul,
This is a resend of a patch from Cyrill. I changed it to inline style.

Cyrill,
This works good on Celleb. Thanks.

Best regards,
Kou Ishizaki


arch/powerpc/platforms/celleb/pci.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/celleb/pci.c b/arch/powerpc/platforms/celleb/pci.c
index 6bc32fd..13ec4a6 100644
--- a/arch/powerpc/platforms/celleb/pci.c
+++ b/arch/powerpc/platforms/celleb/pci.c
@@ -138,8 +138,6 @@ static void celleb_config_read_fake(unsigned char *config, int where,
*val = celleb_fake_config_readl(p);
break;
}
-
- return;
}

static void celleb_config_write_fake(unsigned char *config, int where,
@@ -158,7 +156,6 @@ static void celleb_config_write_fake(unsigned char *config, int where,
celleb_fake_config_writel(val, p);
break;
}
- return;
}

static int celleb_fake_pci_read_config(struct pci_bus *bus,
@@ -351,6 +348,10 @@ static int __init celleb_setup_fake_pci_device(struct device_node *node,
wi1 = of_get_property(node, "vendor-id", NULL);
wi2 = of_get_property(node, "class-code", NULL);
wi3 = of_get_property(node, "revision-id", NULL);
+ if (!wi0 || !wi1 || !wi2 || !wi3) {
+ printk(KERN_ERR "PCI: Missing device tree properties.\n");
+ goto error;
+ }

celleb_config_write_fake(*config, PCI_DEVICE_ID, 2, wi0[0] & 0xffff);
celleb_config_write_fake(*config, PCI_VENDOR_ID, 2, wi1[0] & 0xffff);
@@ -372,6 +373,10 @@ static int __init celleb_setup_fake_pci_device(struct device_node *node,
celleb_setup_pci_base_addrs(hose, devno, fn, num_base_addr);

li = of_get_property(node, "interrupts", &rlen);
+ if (!li) {
+ printk(KERN_ERR "PCI: interrupts not found.\n");
+ goto error;
+ }
val = li[0];
celleb_config_write_fake(*config, PCI_INTERRUPT_PIN, 1, 1);
celleb_config_write_fake(*config, PCI_INTERRUPT_LINE, 1, val);