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: <CANn89i+uJwvGy6HRN4Ym8Q=jSDx=wDEU-5neo=b3C+xJf=pW-g@mail.gmail.com>
Date:   Wed, 15 Mar 2023 17:23:27 -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 5:11 PM Eric Dumazet <edumazet@...gle.com> wrote:
>
> On Wed, Mar 15, 2023 at 5:02 PM Linus Torvalds
> <torvalds@...ux-foundation.org> wrote:
> >
> > On Wed, Mar 15, 2023 at 4:56 PM Eric Dumazet <edumazet@...gle.com> wrote:
> > >
> > > container_of_const() does not detect this bug at compile time, does it ?
> > >
> > > struct sk_buff *skb = ...;
> > >
> > > struct inet_sk *inet = inet_sk(skb);
> >
> > You didn't actually test it, did you?
>
> I thought I did, sorry. I will spend more time on it.

Oh I might have been fooled, because of course we can not use sk for
the macro parameter name.

-ENOTENOUGHSLEEP

Basically something like this should work just fine

diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 6eb8235be67f8b8265cd86782aed2b489e8850ee..caa20a9055310f5ef108f9b1bb43214a3d598b9e
100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -305,11 +305,7 @@ static inline struct sock *skb_to_full_sk(const
struct sk_buff *skb)
        return sk_to_full_sk(skb->sk);
 }

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

 static inline void __inet_sk_copy_descendant(struct sock *sk_to,
                                             const struct sock *sk_from,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ