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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89i+DLp2tDG7DT1bdYvL1o0UBsBzGBA3t4J2P+yn_QLJX2Q@mail.gmail.com>
Date:   Wed, 15 Mar 2023 16:45:52 -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:40 PM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Wed, Mar 15, 2023 at 4:21 PM Linus Torvalds
> <torvalds@...ux-foundation.org> wrote:
> >
> > 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.
>
> I guess that doesn't work, because of how sk_alloc() and friends are set up.
>
> But I do think the networking code should strive to avoid those
> "randomly cast one socket type to another".

Note that my v1 proposed this thing:

#define inet_sk(sk) \
+       _Generic(sk,                                           \
+                const struct sock * : ((const struct inet_sock *)(sk)), \
+                struct sock * : ((struct inet_sock *)(sk)) \
+       )


Jakub feedback was to instead use a common helper, and CCed you on the
discussion.
I do not see yet how to do this 'without cast'

Let me know if you are ok with the v1 approach.

>
> For example, when you have a TCP socket, instead of casting from
> "struct sock *" to "struct tcp_sock *" in tcp_sk(), and getting it all
> wrong wrt const, I think you should do the same thing:
>
>   #define tcp_sock(ptr) container_of(ptr, struct tcp_sock,
> inet_conn.icsk_inet.sk)
>
> to really *show* that you know that "yes, struct tcp_sock contains a
> 'sk' embedded three structures down!".
>
> And no, I did not actually *test* that at all. But it should get
> 'const' right (because container_of() gets const right these days),
> _and_ it actually verifies that the type you claim has another type
> embedded in it actually does so.
>
>                   Linus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ