lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210503070351.GJ1981@kadam>
Date:   Mon, 3 May 2021 10:03:51 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     Bjorn Helgaas <helgaas@...nel.org>
Cc:     Christophe JAILLET <christophe.jaillet@...adoo.fr>,
        Colin King <colin.king@...onical.com>,
        Ryder Lee <ryder.lee@...iatek.com>,
        Jianjun Wang <jianjun.wang@...iatek.com>,
        Lorenzo Pieralisi <lorenzo.pieralisi@....com>,
        Rob Herring <robh@...nel.org>,
        Bjorn Helgaas <bhelgaas@...gle.com>,
        Matthias Brugger <matthias.bgg@...il.com>,
        linux-pci@...r.kernel.org, linux-mediatek@...ts.infradead.org,
        linux-arm-kernel@...ts.infradead.org,
        kernel-janitors@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] PCI: mediatek-gen3: Add missing null pointer check

On Fri, Apr 30, 2021 at 11:34:50AM -0500, Bjorn Helgaas wrote:
> On Fri, Apr 30, 2021 at 09:47:06AM +0200, Christophe JAILLET wrote:
> > Le 29/04/2021 à 13:00, Colin King a écrit :
> > > From: Colin Ian King <colin.king@...onical.com>
> > > 
> > > The call to platform_get_resource_byname can potentially return null, so
> > > add a null pointer check to avoid a null pointer dereference issue.
> > > 
> > > Addresses-Coverity: ("Dereference null return")
> > > Fixes: 441903d9e8f0 ("PCI: mediatek-gen3: Add MediaTek Gen3 driver for MT8192")
> > > Signed-off-by: Colin Ian King <colin.king@...onical.com>
> > > ---
> > >   drivers/pci/controller/pcie-mediatek-gen3.c | 2 ++
> > >   1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
> > > index 20165e4a75b2..3c5b97716d40 100644
> > > --- a/drivers/pci/controller/pcie-mediatek-gen3.c
> > > +++ b/drivers/pci/controller/pcie-mediatek-gen3.c
> > > @@ -721,6 +721,8 @@ static int mtk_pcie_parse_port(struct mtk_pcie_port *port)
> > >   	int ret;
> > >   	regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcie-mac");
> > > +	if (!regs)
> > > +		return -EINVAL;
> > >   	port->base = devm_ioremap_resource(dev, regs);
> > >   	if (IS_ERR(port->base)) {
> > >   		dev_err(dev, "failed to map register base\n");
> > > 
> > 
> > Nitpick:
> >    Using 'devm_platform_ioremap_resource_byname' is slightly less verbose
> > and should please Coverity.
> 
> Not a nitpick at all.  Jianjun is correct that devm_ioremap_resource()
> does check "regs" for NULL and it fails gracefully before trying to
> dereference it, so the extra check shouldn't be needed.  And most
> cases in drivers/pci/ look like this, without the extra check:
> 
>   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "app");
>   base = devm_ioremap_resource(dev, res);
>   if (IS_ERR(base))
>     ...
> 
> If devm_platform_ioremap_resource_byname() keeps Coverity happy, I
> think that's what we should be doing across drivers/pci/.  Coverity
> false positives are a hassle.

Smatch knows that devm_ioremap_resource() will return ERR_PTR(-EINVAL)
when we pass it a NULL.  ;)

regards,
dan carpenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ