linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Young Xiao <92siuyang@gmail.com>,
	Tyrel Datwyler <tyreld@linux.vnet.ibm.com>,
	linux-pci@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PCI/hotplug: fix potential null pointer deference
Date: Thu, 1 Aug 2019 19:14:51 -0500	[thread overview]
Message-ID: <20190802001451.GH151852@google.com> (raw)
In-Reply-To: <CAHp75VcnqpQPTEFsG_bDmAJa4EHucgwoGvyw_XukC6vntdDhow@mail.gmail.com>

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

      reply	other threads:[~2019-08-02  0:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190802001451.GH151852@google.com \
    --to=helgaas@kernel.org \
    --cc=92siuyang@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=tyreld@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).