Linux-PCI Archive on lore.kernel.org
 help / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Young Xiao <92siuyang@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.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: Fri, 14 Jun 2019 16:56:32 +0300
Message-ID: <CAHp75VcnqpQPTEFsG_bDmAJa4EHucgwoGvyw_XukC6vntdDhow@mail.gmail.com> (raw)
In-Reply-To: <1560516085-3101-1-git-send-email-92siuyang@gmail.com>

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

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 12:41 Young Xiao
2019-06-14 13:56 ` Andy Shevchenko [this message]

Reply instructions:

You may reply publically 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=CAHp75VcnqpQPTEFsG_bDmAJa4EHucgwoGvyw_XukC6vntdDhow@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=92siuyang@gmail.com \
    --cc=bhelgaas@google.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

Linux-PCI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pci/0 linux-pci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pci linux-pci/ https://lore.kernel.org/linux-pci \
		linux-pci@vger.kernel.org linux-pci@archiver.kernel.org
	public-inbox-index linux-pci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox