All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI/hotplug: fix potential null pointer deference
@ 2019-06-14 12:41 Young Xiao
  2019-06-14 13:56 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Young Xiao @ 2019-06-14 12:41 UTC (permalink / raw)
  To: bhelgaas, tyreld, andy.shevchenko, linux-pci, linux-kernel; +Cc: Young Xiao

There is otherwise a risk of a null pointer dereference.

Signed-off-by: Young Xiao <92siuyang@gmail.com>
---
 drivers/pci/hotplug/cpqphp_ctrl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index b7f4e1f..3c8399f 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -598,10 +598,11 @@ static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size
 			*head = node->next;
 		} else {
 			prevnode = *head;
-			while (prevnode->next != node)
+			while (prevnode && prevnode->next != node)
 				prevnode = prevnode->next;
 
-			prevnode->next = node->next;
+			if (prevnode)
+				prevnode->next = node->next;
 		}
 		node->next = NULL;
 		break;
@@ -788,10 +789,11 @@ static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
 			*head = node->next;
 		} else {
 			prevnode = *head;
-			while (prevnode->next != node)
+			while (prevnode && prevnode->next != node)
 				prevnode = prevnode->next;
 
-			prevnode->next = node->next;
+			if (prevnode)
+				prevnode->next = node->next;
 		}
 		node->next = NULL;
 		break;
-- 
2.7.4


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

* Re: [PATCH] PCI/hotplug: fix potential null pointer deference
  2019-06-14 12:41 [PATCH] PCI/hotplug: fix potential null pointer deference Young Xiao
@ 2019-06-14 13:56 ` Andy Shevchenko
  2019-08-02  0:14   ` Bjorn Helgaas
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2019-06-14 13:56 UTC (permalink / raw)
  To: Young Xiao
  Cc: Bjorn Helgaas, Tyrel Datwyler, linux-pci, Linux Kernel Mailing List

On Fri, Jun 14, 2019 at 3:40 PM Young Xiao <92siuyang@gmail.com> wrote:
>
> There is otherwise a risk of a null pointer dereference.

Had you analyze the code?
How come that prevnode can become NULL?

> Signed-off-by: Young Xiao <92siuyang@gmail.com>
> ---
>  drivers/pci/hotplug/cpqphp_ctrl.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
> index b7f4e1f..3c8399f 100644
> --- a/drivers/pci/hotplug/cpqphp_ctrl.c
> +++ b/drivers/pci/hotplug/cpqphp_ctrl.c
> @@ -598,10 +598,11 @@ static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size
>                         *head = node->next;
>                 } else {
>                         prevnode = *head;
> -                       while (prevnode->next != node)
> +                       while (prevnode && prevnode->next != node)
>                                 prevnode = prevnode->next;
>
> -                       prevnode->next = node->next;
> +                       if (prevnode)
> +                               prevnode->next = node->next;
>                 }
>                 node->next = NULL;
>                 break;
> @@ -788,10 +789,11 @@ static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
>                         *head = node->next;
>                 } else {
>                         prevnode = *head;
> -                       while (prevnode->next != node)
> +                       while (prevnode && prevnode->next != node)
>                                 prevnode = prevnode->next;
>
> -                       prevnode->next = node->next;
> +                       if (prevnode)
> +                               prevnode->next = node->next;
>                 }
>                 node->next = NULL;
>                 break;
> --
> 2.7.4
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] PCI/hotplug: fix potential null pointer deference
  2019-06-14 13:56 ` Andy Shevchenko
@ 2019-08-02  0:14   ` Bjorn Helgaas
  0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2019-08-02  0:14 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Young Xiao, Tyrel Datwyler, linux-pci, Linux Kernel Mailing List

On Fri, Jun 14, 2019 at 04:56:32PM +0300, Andy Shevchenko wrote:
> On Fri, Jun 14, 2019 at 3:40 PM Young Xiao <92siuyang@gmail.com> wrote:
> >
> > There is otherwise a risk of a null pointer dereference.
> 
> Had you analyze the code?
> How come that prevnode can become NULL?

Dropping this for now.  Young, if there's a scenario where prevnode
can actually be NULL, please mention that in the changelog and repost
this.

> > Signed-off-by: Young Xiao <92siuyang@gmail.com>
> > ---
> >  drivers/pci/hotplug/cpqphp_ctrl.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
> > index b7f4e1f..3c8399f 100644
> > --- a/drivers/pci/hotplug/cpqphp_ctrl.c
> > +++ b/drivers/pci/hotplug/cpqphp_ctrl.c
> > @@ -598,10 +598,11 @@ static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size
> >                         *head = node->next;
> >                 } else {
> >                         prevnode = *head;
> > -                       while (prevnode->next != node)
> > +                       while (prevnode && prevnode->next != node)
> >                                 prevnode = prevnode->next;
> >
> > -                       prevnode->next = node->next;
> > +                       if (prevnode)
> > +                               prevnode->next = node->next;
> >                 }
> >                 node->next = NULL;
> >                 break;
> > @@ -788,10 +789,11 @@ static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
> >                         *head = node->next;
> >                 } else {
> >                         prevnode = *head;
> > -                       while (prevnode->next != node)
> > +                       while (prevnode && prevnode->next != node)
> >                                 prevnode = prevnode->next;
> >
> > -                       prevnode->next = node->next;
> > +                       if (prevnode)
> > +                               prevnode->next = node->next;
> >                 }
> >                 node->next = NULL;
> >                 break;
> > --
> > 2.7.4
> >
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko

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

end of thread, other threads:[~2019-08-02  0:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14 12:41 [PATCH] PCI/hotplug: fix potential null pointer deference Young Xiao
2019-06-14 13:56 ` Andy Shevchenko
2019-08-02  0:14   ` Bjorn Helgaas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.