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: <CANn89iKA3E0CnXD=3EmP8-Ojav-tYEFeBaBu3B7CgzPaX6EC6A@mail.gmail.com>
Date:   Wed, 15 Mar 2023 16:37:14 -0700
From:   Eric Dumazet <edumazet@...gle.com>
To:     Linus Torvalds <torvalds@...ux-foundation.org>
Cc:     Jakub Kicinski <kuba@...nel.org>,
        "David S . Miller" <davem@...emloft.net>,
        Paolo Abeni <pabeni@...hat.com>,
        David Ahern <dsahern@...nel.org>, netdev@...r.kernel.org,
        eric.dumazet@...il.com,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk()

On Wed, Mar 15, 2023 at 4:21 PM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Wed, Mar 15, 2023 at 3:38 PM Eric Dumazet <edumazet@...gle.com> wrote:
> >
> > Maybe something like this?
>
> Please no.
>
> > +#define promote_to_type(ptr, oldtype, newtype)                 \
> > +       _Generic(ptr,                                           \
> > +                const oldtype *: ((const newtype *)(ptr)),     \
> > +                oldtype *: ((newtype *)(ptr))                  \
> > +       )
>
> That's just a very ugly way to just do a cast. It's wrong.
>
> > +#define inet_sk(sk) promote_to_type(sk, struct sock, struct inet_sock)
>
> This is horrid.
>
> Why isn't this just doing
>
>    #define inet_sk(ptr) container_of(ptr, struct inet_sock, sk)
>
> which is different from a plain cast in that it actually checks that
> "yes, struct inet_sock has a member called 'sk' that has the right
> type, so now we can convert from that sk to the containing structure".
>
> That's very different from just randomly casting a pointer to another
> pointer, like the current inet_sk() does, and like that disgusting
> promote_to_type() macro does.
>
> We really strive for proper type safety in the kernel. And that very
> much means *not* doing random casts.
>
> At least that "inet_sk(sk)" version using generics didn't take random
> pointer types. But I really don't see why you don't just use
> "container_of()", which is actually type-safe, and would allow "struct
> inet_sock" to contain the "struct sock" somewhere else than in the
> first field.
>
> Hmm? Am I missing something that is happening in linux-next?


Yep. my goal was to have const awareness.

https://patchwork.kernel.org/project/netdevbpf/patch/20230315154245.3405750-2-edumazet@google.com/

(and whole series in
https://patchwork.kernel.org/project/netdevbpf/list/?series=730398&state=*
)

This:

#define inet_sk(ptr) container_of(ptr, struct inet_sock, sk)

does not really cover what I wanted, does it ?

>
>                 Linus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ