netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays
@ 2023-01-05 22:15 Kees Cook
  2023-01-06 16:00 ` Gustavo A. R. Silva
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kees Cook @ 2023-01-05 22:15 UTC (permalink / raw)
  To: David S. Miller
  Cc: Kees Cook, Hideaki YOSHIFUJI, David Ahern, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Gustavo A. R. Silva, netdev,
	linux-kernel, linux-hardening

Zero-length arrays are deprecated[1]. Replace struct ipv6_rpl_sr_hdr's
"segments" union of 0-length arrays with flexible arrays. Detected with
GCC 13, using -fstrict-flex-arrays=3:

In function 'rpl_validate_srh',
    inlined from 'rpl_build_state' at ../net/ipv6/rpl_iptunnel.c:96:7:
../net/ipv6/rpl_iptunnel.c:60:28: warning: array subscript <unknown> is outside array bounds of 'struct in6_addr[0]' [-Warray-bounds=]
   60 |         if (ipv6_addr_type(&srh->rpl_segaddr[srh->segments_left - 1]) &
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/net/rpl.h:12,
                 from ../net/ipv6/rpl_iptunnel.c:13:
../include/uapi/linux/rpl.h: In function 'rpl_build_state':
../include/uapi/linux/rpl.h:40:33: note: while referencing 'addr'
   40 |                 struct in6_addr addr[0];
      |                                 ^~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: David Ahern <dsahern@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/uapi/linux/rpl.h | 4 ++--
 net/ipv6/rpl_iptunnel.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/rpl.h b/include/uapi/linux/rpl.h
index 708adddf9f13..7c8970e5b84b 100644
--- a/include/uapi/linux/rpl.h
+++ b/include/uapi/linux/rpl.h
@@ -37,8 +37,8 @@ struct ipv6_rpl_sr_hdr {
 #endif
 
 	union {
-		struct in6_addr addr[0];
-		__u8 data[0];
+		__DECLARE_FLEX_ARRAY(struct in6_addr, addr);
+		__DECLARE_FLEX_ARRAY(__u8, data);
 	} segments;
 } __attribute__((packed));
 
diff --git a/net/ipv6/rpl_iptunnel.c b/net/ipv6/rpl_iptunnel.c
index ff691d9f4a04..b1c028df686e 100644
--- a/net/ipv6/rpl_iptunnel.c
+++ b/net/ipv6/rpl_iptunnel.c
@@ -13,7 +13,7 @@
 #include <net/rpl.h>
 
 struct rpl_iptunnel_encap {
-	struct ipv6_rpl_sr_hdr srh[0];
+	DECLARE_FLEX_ARRAY(struct ipv6_rpl_sr_hdr, srh);
 };
 
 struct rpl_lwt {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays
  2023-01-05 22:15 [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays Kees Cook
@ 2023-01-06 16:00 ` Gustavo A. R. Silva
  2023-01-06 16:16 ` David Ahern
  2023-01-07  3:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-01-06 16:00 UTC (permalink / raw)
  To: Kees Cook
  Cc: David S. Miller, Hideaki YOSHIFUJI, David Ahern, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

On Thu, Jan 05, 2023 at 02:15:37PM -0800, Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct ipv6_rpl_sr_hdr's
> "segments" union of 0-length arrays with flexible arrays. Detected with
> GCC 13, using -fstrict-flex-arrays=3:
> 
> In function 'rpl_validate_srh',
>     inlined from 'rpl_build_state' at ../net/ipv6/rpl_iptunnel.c:96:7:
> ../net/ipv6/rpl_iptunnel.c:60:28: warning: array subscript <unknown> is outside array bounds of 'struct in6_addr[0]' [-Warray-bounds=]
>    60 |         if (ipv6_addr_type(&srh->rpl_segaddr[srh->segments_left - 1]) &
>       |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from ../include/net/rpl.h:12,
>                  from ../net/ipv6/rpl_iptunnel.c:13:
> ../include/uapi/linux/rpl.h: In function 'rpl_build_state':
> ../include/uapi/linux/rpl.h:40:33: note: while referencing 'addr'
>    40 |                 struct in6_addr addr[0];
>       |                                 ^~~~
> 
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
> Cc: David Ahern <dsahern@kernel.org>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>  include/uapi/linux/rpl.h | 4 ++--
>  net/ipv6/rpl_iptunnel.c  | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/uapi/linux/rpl.h b/include/uapi/linux/rpl.h
> index 708adddf9f13..7c8970e5b84b 100644
> --- a/include/uapi/linux/rpl.h
> +++ b/include/uapi/linux/rpl.h
> @@ -37,8 +37,8 @@ struct ipv6_rpl_sr_hdr {
>  #endif
>  
>  	union {
> -		struct in6_addr addr[0];
> -		__u8 data[0];
> +		__DECLARE_FLEX_ARRAY(struct in6_addr, addr);
> +		__DECLARE_FLEX_ARRAY(__u8, data);
>  	} segments;
>  } __attribute__((packed));
>  
> diff --git a/net/ipv6/rpl_iptunnel.c b/net/ipv6/rpl_iptunnel.c
> index ff691d9f4a04..b1c028df686e 100644
> --- a/net/ipv6/rpl_iptunnel.c
> +++ b/net/ipv6/rpl_iptunnel.c
> @@ -13,7 +13,7 @@
>  #include <net/rpl.h>
>  
>  struct rpl_iptunnel_encap {
> -	struct ipv6_rpl_sr_hdr srh[0];
> +	DECLARE_FLEX_ARRAY(struct ipv6_rpl_sr_hdr, srh);
>  };
>  
>  struct rpl_lwt {
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays
  2023-01-05 22:15 [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays Kees Cook
  2023-01-06 16:00 ` Gustavo A. R. Silva
@ 2023-01-06 16:16 ` David Ahern
  2023-01-07  3:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2023-01-06 16:16 UTC (permalink / raw)
  To: Kees Cook, David S. Miller
  Cc: Hideaki YOSHIFUJI, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Gustavo A. R. Silva, netdev, linux-kernel, linux-hardening

On 1/5/23 3:15 PM, Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct ipv6_rpl_sr_hdr's
> "segments" union of 0-length arrays with flexible arrays. Detected with
> GCC 13, using -fstrict-flex-arrays=3:
> 
> In function 'rpl_validate_srh',
>     inlined from 'rpl_build_state' at ../net/ipv6/rpl_iptunnel.c:96:7:
> ../net/ipv6/rpl_iptunnel.c:60:28: warning: array subscript <unknown> is outside array bounds of 'struct in6_addr[0]' [-Warray-bounds=]
>    60 |         if (ipv6_addr_type(&srh->rpl_segaddr[srh->segments_left - 1]) &
>       |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from ../include/net/rpl.h:12,
>                  from ../net/ipv6/rpl_iptunnel.c:13:
> ../include/uapi/linux/rpl.h: In function 'rpl_build_state':
> ../include/uapi/linux/rpl.h:40:33: note: while referencing 'addr'
>    40 |                 struct in6_addr addr[0];
>       |                                 ^~~~
> 
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
> Cc: David Ahern <dsahern@kernel.org>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  include/uapi/linux/rpl.h | 4 ++--
>  net/ipv6/rpl_iptunnel.c  | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays
  2023-01-05 22:15 [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays Kees Cook
  2023-01-06 16:00 ` Gustavo A. R. Silva
  2023-01-06 16:16 ` David Ahern
@ 2023-01-07  3:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-07  3:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: davem, yoshfuji, dsahern, edumazet, kuba, pabeni, gustavoars,
	netdev, linux-kernel, linux-hardening

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  5 Jan 2023 14:15:37 -0800 you wrote:
> Zero-length arrays are deprecated[1]. Replace struct ipv6_rpl_sr_hdr's
> "segments" union of 0-length arrays with flexible arrays. Detected with
> GCC 13, using -fstrict-flex-arrays=3:
> 
> In function 'rpl_validate_srh',
>     inlined from 'rpl_build_state' at ../net/ipv6/rpl_iptunnel.c:96:7:
> ../net/ipv6/rpl_iptunnel.c:60:28: warning: array subscript <unknown> is outside array bounds of 'struct in6_addr[0]' [-Warray-bounds=]
>    60 |         if (ipv6_addr_type(&srh->rpl_segaddr[srh->segments_left - 1]) &
>       |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from ../include/net/rpl.h:12,
>                  from ../net/ipv6/rpl_iptunnel.c:13:
> ../include/uapi/linux/rpl.h: In function 'rpl_build_state':
> ../include/uapi/linux/rpl.h:40:33: note: while referencing 'addr'
>    40 |                 struct in6_addr addr[0];
>       |                                 ^~~~
> 
> [...]

Here is the summary with links:
  - net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays
    https://git.kernel.org/netdev/net-next/c/e8d283b6cf0e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-07  3:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-05 22:15 [PATCH] net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays Kees Cook
2023-01-06 16:00 ` Gustavo A. R. Silva
2023-01-06 16:16 ` David Ahern
2023-01-07  3:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).