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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK8P3a0Q+-zYhkw_CpanXis7iM=9Hqw1Et8-GwxYw5d5Qy-sQA@mail.gmail.com>
Date:   Wed, 8 Jan 2020 09:18:07 +0100
From:   Arnd Bergmann <arnd@...db.de>
To:     Miquel Raynal <miquel.raynal@...tlin.com>
Cc:     Richard Weinberger <richard@....at>,
        Vignesh Raghavendra <vigneshr@...com>,
        Oleksandr Natalenko <oleksandr@...hat.com>,
        Wenwen Wang <wenwen@...uga.edu>,
        linux-mtd <linux-mtd@...ts.infradead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] mtd: sm_ftl: fix NULL pointer warning

On Wed, Jan 8, 2020 at 9:15 AM Miquel Raynal <miquel.raynal@...tlin.com> wrote:
>
> Hi Arnd,
>
> Arnd Bergmann <arnd@...db.de> wrote on Tue,  7 Jan 2020 22:24:52 +0100:
>
> > With gcc -O3, we get a new warning:
> >
> > In file included from arch/arm64/include/asm/processor.h:28,
> >                  from drivers/mtd/sm_ftl.c:8:
> > In function 'memset',
> >     inlined from 'sm_read_sector.constprop' at drivers/mtd/sm_ftl.c:250:3:
> > include/linux/string.h:411:9: error: argument 1 null where non-null expected [-Werror=nonnull]
> >   return __builtin_memset(p, c, size);
> >
> > From all I can tell, this cannot happen (the function is called
> > either with a NULL buffer or with a -1 block number but not both),
> > but adding a check makes it more robust and avoids the warning.
> >
> > Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
> > Signed-off-by: Arnd Bergmann <arnd@...db.de>
> > ---
> >  drivers/mtd/sm_ftl.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
> > index 4744bf94ad9a..b9f272408c4d 100644
> > --- a/drivers/mtd/sm_ftl.c
> > +++ b/drivers/mtd/sm_ftl.c
> > @@ -247,7 +247,8 @@ static int sm_read_sector(struct sm_ftl *ftl,
> >
> >       /* FTL can contain -1 entries that are by default filled with bits */
> >       if (block == -1) {
> > -             memset(buffer, 0xFF, SM_SECTOR_SIZE);
> > +             if (buffer)
> > +                     memset(buffer, 0xFF, SM_SECTOR_SIZE);
> >               return 0;
> >       }
> >
>
> What about a simpler form:
>
>         if (buffer && block == -1) { ...
>
> Instead of an additional indentation level?

That would fail to return early from the function if we ever get block==-1
and buffer==NULL, probably resulting is worse problems later.

       Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ