Skip to content

Commit

Permalink
net: ipv6: rpl_iptunnel: Replace 0-length arrays with flexible arrays
Browse files Browse the repository at this point in the history
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: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20230105221533.never.711-kees@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Kees Cook authored and Jakub Kicinski committed Jan 7, 2023
1 parent 0b5dfa3 commit e8d283b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/uapi/linux/rpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/rpl_iptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e8d283b

Please sign in to comment.