diff mbox series

[RFC] xfrm: convert alg_key to flexible array member

Message ID 20220524204741.980721-1-stephen@networkplumber.org (mailing list archive)
State RFC
Headers show
Series [RFC] xfrm: convert alg_key to flexible array member | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger May 24, 2022, 8:47 p.m. UTC
Iproute2 build generates a warning when built with gcc-12.
This is because the alg_key in xfrm.h API has zero size
array element instead of flexible array.

    CC       xfrm_state.o
In function ‘xfrm_algo_parse’,
    inlined from ‘xfrm_state_modify.constprop’ at xfrm_state.c:573:5:
xfrm_state.c:162:32: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  162 |                         buf[j] = val;
      |                         ~~~~~~~^~~~~

This patch convert the alg_key into flexible array member.
There are other zero size arrays here that should be converted as
well.

This patch is RFC only since it is only compile tested and
passes trivial iproute2 tests.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 include/uapi/linux/xfrm.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Herbert Xu May 25, 2022, 12:15 a.m. UTC | #1
On Tue, May 24, 2022 at 01:47:40PM -0700, Stephen Hemminger wrote:
> Iproute2 build generates a warning when built with gcc-12.
> This is because the alg_key in xfrm.h API has zero size
> array element instead of flexible array.
> 
>     CC       xfrm_state.o
> In function ‘xfrm_algo_parse’,
>     inlined from ‘xfrm_state_modify.constprop’ at xfrm_state.c:573:5:
> xfrm_state.c:162:32: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
>   162 |                         buf[j] = val;
>       |                         ~~~~~~~^~~~~
> 
> This patch convert the alg_key into flexible array member.
> There are other zero size arrays here that should be converted as
> well.
> 
> This patch is RFC only since it is only compile tested and
> passes trivial iproute2 tests.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  include/uapi/linux/xfrm.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Steffen Klassert June 2, 2022, 10:45 a.m. UTC | #2
On Tue, May 24, 2022 at 01:47:40PM -0700, Stephen Hemminger wrote:
> Iproute2 build generates a warning when built with gcc-12.
> This is because the alg_key in xfrm.h API has zero size
> array element instead of flexible array.
> 
>     CC       xfrm_state.o
> In function ‘xfrm_algo_parse’,
>     inlined from ‘xfrm_state_modify.constprop’ at xfrm_state.c:573:5:
> xfrm_state.c:162:32: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
>   162 |                         buf[j] = val;
>       |                         ~~~~~~~^~~~~
> 
> This patch convert the alg_key into flexible array member.
> There are other zero size arrays here that should be converted as
> well.
> 
> This patch is RFC only since it is only compile tested and
> passes trivial iproute2 tests.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

I've put this today to our test systems and it showed no problems,
so we can integrate it after the merge window.
Steffen Klassert June 23, 2022, 10:49 a.m. UTC | #3
On Thu, Jun 02, 2022 at 12:45:15PM +0200, Steffen Klassert wrote:
> On Tue, May 24, 2022 at 01:47:40PM -0700, Stephen Hemminger wrote:
> > Iproute2 build generates a warning when built with gcc-12.
> > This is because the alg_key in xfrm.h API has zero size
> > array element instead of flexible array.
> > 
> >     CC       xfrm_state.o
> > In function ‘xfrm_algo_parse’,
> >     inlined from ‘xfrm_state_modify.constprop’ at xfrm_state.c:573:5:
> > xfrm_state.c:162:32: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
> >   162 |                         buf[j] = val;
> >       |                         ~~~~~~~^~~~~
> > 
> > This patch convert the alg_key into flexible array member.
> > There are other zero size arrays here that should be converted as
> > well.
> > 
> > This patch is RFC only since it is only compile tested and
> > passes trivial iproute2 tests.
> > 
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> 
> I've put this today to our test systems and it showed no problems,
> so we can integrate it after the merge window.

This is now applied to ipsec-next, thanks!
diff mbox series

Patch

diff --git a/include/uapi/linux/xfrm.h b/include/uapi/linux/xfrm.h
index 65e13a099b1a..3ed61df9cc91 100644
--- a/include/uapi/linux/xfrm.h
+++ b/include/uapi/linux/xfrm.h
@@ -102,21 +102,21 @@  struct xfrm_replay_state_esn {
 struct xfrm_algo {
 	char		alg_name[64];
 	unsigned int	alg_key_len;    /* in bits */
-	char		alg_key[0];
+	char		alg_key[];
 };
 
 struct xfrm_algo_auth {
 	char		alg_name[64];
 	unsigned int	alg_key_len;    /* in bits */
 	unsigned int	alg_trunc_len;  /* in bits */
-	char		alg_key[0];
+	char		alg_key[];
 };
 
 struct xfrm_algo_aead {
 	char		alg_name[64];
 	unsigned int	alg_key_len;	/* in bits */
 	unsigned int	alg_icv_len;	/* in bits */
-	char		alg_key[0];
+	char		alg_key[];
 };
 
 struct xfrm_stats {