[4.15] crypto: adjust rijndaelEncrypt() prototype for gcc11
PATCH 1/1 [4.15] crypto: adjust rijndaelEncrypt() prototype for gcc11
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'
55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [],
| ^~~~~~~~~~~~~~~~~~~~~~
rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=]
865 | u8 ct[16])
| ~~~^~~~~~
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:56:13: note: previously declared as 'unsigned char[]'
56 | unsigned char []);
| ^~~~~~~~~~~~~~~~While it's not really clear to me why it would complain only for arg 4, the adjustment to make is obvious and riskfree also for arg 3: Simply declare the correct array dimension right away. This then allows compilers to apply checking at call sites, which seems desirable anyway.
For the moment I'm leaving untouched the disagreement between u8/u32 used in the function definition and unsigned {char,int} used in the declaration, as making this consistent would call for touching further functions.
---
There are quite a few more issues with gcc11, but from my brief initial inspection I'm suspecting (hoping) it'll rather be the compiler which will get further changed by the time their release gets finalized. Just one example:
.../xen/include/xen/string.h:101:27: error: '__builtin_memcmp' specified bound 4 exceeds source size 0 [-Werror=stringop-overread]
101 | #define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
mpparse.c:722:13: note: in expansion of macro 'memcmp'
722 | if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 &&
| ^~~~~~Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
xen/include/crypto/rijndael.h +2 -2
@@ -52,7 +52,7 @@int rijndaelKeySetupEnc (unsigned int [],const unsigned char [],int );int rijndaelKeySetupDec (unsigned int [],const unsigned char [],int ); -void rijndaelEncrypt (const unsigned int [],int ,const unsigned char [], -unsigned char []); +void rijndaelEncrypt (const unsigned int [],int ,const unsigned char [16 ], +unsigned char [16 ]);#endif /* __RIJNDAEL_H */
Hi Jan,
Quoted 14 lines · Jan Beulich
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~ rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=] 865 | u8 ct[16]) | ~~~^~~~~~ In file included from rijndael.c:33: .../xen/include/crypto/rijndael.h:56:13: note: previously declared as 'unsigned char[]' 56 | unsigned char []); | ^~~~~~~~~~~~~~~~
Quoted 4 lines
While it's not really clear to me why it would complain only for arg 4, the adjustment to make is obvious and riskfree also for arg 3: Simply declare the correct array dimension right away. This then allows compilers to apply checking at call sites, which seems desirable anyway.
I am a bit confused, if GCC is not complaining for arg3, then what is the following error message for:
Quoted 18 lines
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~For the moment I'm leaving untouched the disagreement between u8/u32 used in the function definition and unsigned {char,int} used in the declaration, as making this consistent would call for touching further functions.
Reported-by Charles Arnold <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
There are quite a few more issues with gcc11, but from my brief initial inspection I'm suspecting (hoping) it'll rather be the compiler which will get further changed by the time their release gets finalized. Just one example:
Quoted 8 lines
.../xen/include/xen/string.h:101:27: error: '__builtin_memcmp' specified bound 4 exceeds source size 0 [-Werror=stringop-overread]
101 | #definememcmp(s1, s2, n)__builtin_memcmp(s1, s2, n)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ mpparse.c:722:13: note: in expansion of macro 'memcmp' 722 | if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 && | ^~~~~~Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
It looks like there is a report on the redhat bug tracker for it [1]. Do you know if there is a bug report on the GCC tracker as well?
Quoted 5 lines
xen/include/crypto/rijndael.h line 58
Quoted 9 lines
xen/include/crypto/rijndael.h +2
-2@@ -52,7 +52,7 @@int rijndaelKeySetupEnc (unsigned int [],const unsigned char [],int );int rijndaelKeySetupDec (unsigned int [],const unsigned char [],int ); -void rijndaelEncrypt (const unsigned int [],int ,const unsigned char [], -unsigned char []); +void rijndaelEncrypt (const unsigned int [],int ,const unsigned char [16 ], +unsigned char [16 ]);#endif /* __RIJNDAEL_H */
Cheers,
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1892100
Signature · 1 line
Julien Grall
Quoted 23 lines · Julien Grall
Quoted 14 lines · Jan Beulich
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~ rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=] 865 | u8 ct[16]) | ~~~^~~~~~ In file included from rijndael.c:33: .../xen/include/crypto/rijndael.h:56:13: note: previously declared as 'unsigned char[]' 56 | unsigned char []); | ^~~~~~~~~~~~~~~~Quoted 4 lines
While it's not really clear to me why it would complain only for arg 4, the adjustment to make is obvious and riskfree also for arg 3: Simply declare the correct array dimension right away. This then allows compilers to apply checking at call sites, which seems desirable anyway.
I am a bit confused, if GCC is not complaining for arg3, then what is the following error message for:
Quoted 7 lines
Quoted 2 lines
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as'const unsigned char[]'
Quoted 1 line
55 | void rijndaelEncrypt(const unsigned int [], int, constunsigned char [],
Quoted 1 line
|^~~~~~~~~~~~~~~~~~~~~~
Hmm, good point. I didn't observe this myself, and simply copied the part of the error message that I was handed. I suppose there was an "error: argument 3 of type ..." there then as well. Charles - any chance you could confirm this, and perhaps even quote the full set of error messages in our internal patch?
I'll adjust the wording of the description in any event.
Quoted 12 lines
Quoted 12 lines
There are quite a few more issues with gcc11, but from my brief initial inspection I'm suspecting (hoping) it'll rather be the compiler which will get further changed by the time their release gets finalized. Just one example:
.../xen/include/xen/string.h:101:27: error: '__builtin_memcmp' specified bound 4 exceeds source size 0 [-Werror=stringop-overread]
101 | #definememcmp(s1, s2, n)__builtin_memcmp(s1, s2, n)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ mpparse.c:722:13: note: in expansion of macro 'memcmp' 722 | if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 && | ^~~~~~
Quoted 4 lines
Quoted 1 line
Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
It looks like there is a report on the redhat bug tracker for it [1]. Do you know if there is a bug report on the GCC tracker as well?
I have no idea, to be honest.
Jan
Jan Beulich writes ("Re: [PATCH][4.15] crypto: adjust rijndaelEncrypt() prototype for gcc11"):
Quoted 10 lines · Julien Grall
Quoted 9 lines · Jan Beulich
Quoted 8 lines
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=]
865 | u8 ct[16])
I think this is an erroneous compiler warning.
It has been idiomatic in some codebases for a long time to write
const unsigned char[]
as a formal parameter for an array (of whatever size).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
.../xen/include/xen/string.h:101:27: error: '__builtin_memcmp' specified bound 4 exceeds source size 0 [-Werror=stringop-overread]
101 | #definememcmp(s1, s2, n)__builtin_memcmp(s1, s2, n)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ mpparse.c:722:13: note: in expansion of macro 'memcmp' 722 | if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 && | ^~~~~~
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
It looks like there is a report on the redhat bug tracker for it [1]. Do you know if there is a bug report on the GCC tracker as well?
I have no idea, to be honest.
This erroneous message makes me think that there is simply a bug in this version of GCC, where formal parameters declared as
const unsigned char[]
are treated as
const unsigned char[0]
rather than as
const unsigned char*
Ian.
Quoted 12 lines · Ian Jackson
Jan Beulich writes ("Re: [PATCH][4.15] crypto: adjust
rijndaelEncrypt()prototype for gcc11"):Quoted 10 lines · Julien Grall
Quoted 9 lines · Jan Beulich
Quoted 8 lines
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~ rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=] 865 | u8 ct[16])
Quoted 5 lines
I think this is an erroneous compiler warning.
It has been idiomatic in some codebases for a long time to write
const unsigned char[]as a formal parameter for an array (of whatever size).
AFAICT, this is not what GCC is trying to warn about. It is complaining that the prototype and the declaration doesn't use the same signature.
Indeed, the former is using [] while the declaration is using [16].
So compiler is working as intended when -Warray-parameter is selected (see [1]).
[1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Signature · 1 line
Julien Grall
Julien Grall writes ("Re: [PATCH][4.15] crypto: adjust rijndaelEncrypt() prototype for gcc11"):
Quoted 2 lines · Ian Jackson
Quoted 1 line
Jan Beulich writes ("Re: [PATCH][4.15] crypto: adjust
rijndaelEncrypt()prototype for gcc11"):
...
Quoted 6 lines
Quoted 3 lines
It has been idiomatic in some codebases for a long time to write
const unsigned char[]as a formal parameter for an array (of whatever size).
AFAICT, this is not what GCC is trying to warn about. It is complaining that the prototype and the declaration doesn't use the same signature.
Oh! I would have to check whether that is legal (I would guess probably it is UB because the C authors hate us all) but I agree that the warning is justified and the code should be changed.
Sorry for the misunderstanding.
Ian.
Quoted 8 lines · Ian Jackson
Julien Grall writes ("Re: [PATCH][4.15] crypto: adjust
rijndaelEncrypt()prototype for gcc11"):Quoted 2 lines · Ian Jackson
Quoted 1 line
Jan Beulich writes ("Re: [PATCH][4.15] crypto: adjust
rijndaelEncrypt()prototype for gcc11"):...
Quoted 4 lines
Quoted 3 lines
It has been idiomatic in some codebases for a long time to write
const unsigned char[]as a formal parameter for an array (of whatever size).
Quoted 6 lines
Quoted 2 lines
AFAICT, this is not what GCC is trying to warn about. It is complaining that the prototype and the declaration doesn't use the same signature.
Oh! I would have to check whether that is legal (I would guess probably it is UB because the C authors hate us all) but I agree that the warning is justified and the code should be changed.
May I translate this into a release ack then?
Jan
Quoted 32 lines · Ian Jackson
Jan Beulich writes ("Re: [PATCH][4.15] crypto: adjust
rijndaelEncrypt()prototype for gcc11"):Quoted 10 lines · Julien Grall
Quoted 9 lines · Jan Beulich
Quoted 8 lines
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=]
865 | u8 ct[16])I think this is an erroneous compiler warning.
It has been idiomatic in some codebases for a long time to write
const unsigned char[]as a formal parameter for an array (of whatever size).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
.../xen/include/xen/string.h:101:27: error: '__builtin_memcmp' specified bound 4 exceeds source size 0 [-Werror=stringop-overread]
101 | #definememcmp(s1, s2, n)__builtin_memcmp(s1, s2, n)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ mpparse.c:722:13: note: in expansion of macro 'memcmp' 722 | if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 && | ^~~~~~Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
It looks like there is a report on the redhat bug tracker for it [1]. Do you know if there is a bug report on the GCC tracker as well?
I have no idea, to be honest.
Quoted 7 lines
This erroneous message makes me think that there is simply a bug in this version of GCC, where formal parameters declared as
const unsigned char[]are treated as
const unsigned char[0]
rather than as
const unsigned char*
I don't think so, no. In addition to what Julien has said, I think the intention here is that the compiler can check that both consumer and producers of arguments obey to the strictest available bounds of such an array, no matter that at the syntactic level char[N] and char[] both convert to char* when used in prototypes.
Jan
Julien Grall
Reviewed-byQuoted 32 lines · Jan Beulich
Quoted 23 lines · Julien Grall
Quoted 14 lines · Jan Beulich
The upcoming release complains, not entirely unreasonably:
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as 'const unsigned char[]'55 | void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], | ^~~~~~~~~~~~~~~~~~~~~~ rijndael.c:865:8: error: argument 4 of type 'u8[16]' {aka 'unsigned char[16]'} with mismatched bound [-Werror=array-parameter=] 865 | u8 ct[16]) | ~~~^~~~~~ In file included from rijndael.c:33: .../xen/include/crypto/rijndael.h:56:13: note: previously declared as 'unsigned char[]' 56 | unsigned char []); | ^~~~~~~~~~~~~~~~Quoted 4 lines
While it's not really clear to me why it would complain only for arg 4, the adjustment to make is obvious and riskfree also for arg 3: Simply declare the correct array dimension right away. This then allows compilers to apply checking at call sites, which seems desirable anyway.
I am a bit confused, if GCC is not complaining for arg3, then what is the following error message for:
Quoted 7 lines
Quoted 2 lines
In file included from rijndael.c:33:
.../xen/include/crypto/rijndael.h:55:53: note: previously declared as'const unsigned char[]'
Quoted 1 line
55 | void rijndaelEncrypt(const unsigned int [], int, constunsigned char [],
Quoted 1 line
|^~~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines
Hmm, good point. I didn't observe this myself, and simply copied the part of the error message that I was handed. I suppose there was an "error: argument 3 of type ..." there then as well. Charles - any chance you could confirm this, and perhaps even quote the full set of error messages in our internal patch?
I'll adjust the wording of the description in any event.
With the description adjusted:
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
There are quite a few more issues with gcc11, but from my brief initial inspection I'm suspecting (hoping) it'll rather be the compiler which will get further changed by the time their release gets finalized. Just one example:
.../xen/include/xen/string.h:101:27: error: '__builtin_memcmp' specified bound 4 exceeds source size 0 [-Werror=stringop-overread]101 | #define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ mpparse.c:722:13: note: in expansion of macro 'memcmp' 722 | if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 && | ^~~~~~
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
It looks like there is a report on the redhat bug tracker for it [1]. Do you know if there is a bug report on the GCC tracker as well?
I have no idea, to be honest.
I had a look and couldn't find any. It might be worth to fill one in case they are not aware.
Cheers,
Signature · 1 line
Julien Grall
Jan Beulich writes ("[PATCH][4.15] crypto: adjust rijndaelEncrypt() prototype for gcc11"):
Quoted 5 lines
Clearly neither the 1st nor the 2nd argument have a "source size" of 0.
xen/include/crypto/rijndael.h line 58
Quoted 9 lines
xen/include/crypto/rijndael.h +2
-2@@ -52,7 +52,7 @@int rijndaelKeySetupEnc (unsigned int [],const unsigned char [],int );int rijndaelKeySetupDec (unsigned int [],const unsigned char [],int ); -void rijndaelEncrypt (const unsigned int [],int ,const unsigned char [], -unsigned char []); +void rijndaelEncrypt (const unsigned int [],int ,const unsigned char [16 ], +unsigned char [16 ]);#endif /* __RIJNDAEL_H */