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+k3fcSw58owpr70eM_uSM5QUqEb_4y5wpXOKEz30+vvg@mail.gmail.com>
Date:   Thu, 9 Mar 2023 15:59:51 +0100
From:   Eric Dumazet <edumazet@...gle.com>
To:     Gavin Li <gavinl@...dia.com>
Cc:     davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
        roopa@...dia.com, eng.alaamohamedsoliman.am@...il.com,
        bigeasy@...utronix.de, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org, gavi@...dia.com, roid@...dia.com,
        maord@...dia.com, saeedm@...dia.com
Subject: Re: [PATCH net-next v6 4/5] ip_tunnel: Preserve pointer const in ip_tunnel_info_opts

On Thu, Mar 9, 2023 at 2:48 PM Gavin Li <gavinl@...dia.com> wrote:
>
> Change ip_tunnel_info_opts( ) from static function to macro to cast return
> value and preserve the const-ness of the pointer.
>
> Signed-off-by: Gavin Li <gavinl@...dia.com>
> ---
>  include/net/ip_tunnels.h | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
> index fca357679816..3e5c102b841f 100644
> --- a/include/net/ip_tunnels.h
> +++ b/include/net/ip_tunnels.h
> @@ -67,6 +67,12 @@ struct ip_tunnel_key {
>         GENMASK((sizeof_field(struct ip_tunnel_info,            \
>                               options_len) * BITS_PER_BYTE) - 1, 0)
>
> +#define ip_tunnel_info_opts(info)                              \
> +       _Generic(info,                                          \
> +               const typeof(*(info)) * : ((const void *)((info) + 1)),\
> +               default : ((void *)((info) + 1))                \
> +       )
> +

Hmm...

This looks quite dangerous, we lost type safety with the 'default'
case, with all these casts.

What about using something cleaner instead ?

(Not sure why we do not have an available generic helper for this kind
of repetitive things)

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index fca3576798166416982ee6a9100b003810c49830..7f26e07c5f3059d426b31529e4d1c3adec23d70f
100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -485,10 +485,11 @@ static inline void iptunnel_xmit_stats(struct
net_device *dev, int pkt_len)
        }
 }

-static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info)
-{
-       return info + 1;
-}
+#define ip_tunnel_info_opts(info)                              \
+       (_Generic(info,                                         \
+                const struct ip_tunnel_info * : ((info) + 1),  \
+                struct ip_tunnel_info * : ((info) + 1))        \
+       )

 static inline void ip_tunnel_info_opts_get(void *to,
                                           const struct ip_tunnel_info *info)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ