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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 27 Oct 2020 15:51:22 +0100
From:   Arnd Bergmann <arnd@...nel.org>
To:     Christoph Hellwig <hch@...radead.org>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Tejun Heo <tj@...nel.org>,
        Alexander Viro <viro@...iv.linux.org.uk>,
        Nathan Chancellor <natechancellor@...il.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Amir Goldstein <amir73il@...il.com>, Jan Kara <jack@...e.cz>,
        Andrew Morton <akpm@...ux-foundation.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Linux FS-devel Mailing List <linux-fsdevel@...r.kernel.org>,
        clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH] seq_file: fix clang warning for NULL pointer arithmetic

On Tue, Oct 27, 2020 at 11:45 AM Christoph Hellwig <hch@...radead.org> wrote:
>
> > index f277d023ebcd..b55e6ef4d677 100644
> > --- a/fs/kernfs/file.c
> > +++ b/fs/kernfs/file.c
> > @@ -124,7 +124,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
> >                * The same behavior and code as single_open().  Returns
> >                * !NULL if pos is at the beginning; otherwise, NULL.
> >                */
> > -             return NULL + !*ppos;
> > +             return (void *)(uintptr_t)!*ppos;
>
> Yikes.  This is just horrible, why bnot the completely obvious:
>
>         if (ops->seq_start) {
>                 ...
>                 return next;
>         }
>
>         if (*ppos)
>                 return NULL;
>         return ppos; /* random cookie */

I was trying to not change the behavior, but I guess we can do better
than either the original version mine. Not sure I'd call your version
'obvious' either though, at least it was immediately clear to me that
returning an unrelated pointer here is the right thing to do (it works,
since it is guaranteed to be neither NULL nor an error pointer
and it is never dereferenced, but it's still odd).

I'd rather define something like

#define SEQ_OPEN_SINGLE (void *)1ul

and return that here. I'll send a patch doing that, let me know what
you think.

     Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ