cipher: add AES-CMAC hashing support
PATCH 1/1 cipher: add AES-CMAC hashing support
The algorythm is supported in the kernel, and it is used heavily by Bluetooth Mesh, and is the one Mesh required algorythm missing from ELL.
--- ell/cipher.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ell/cipher.h | 16 ++++++++++ unit/test-cipher.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+)
ell/cipher.c +88 -0
@@ -90,6 +90,7 @@ struct af_alg_iv {static uint32_t supported_ciphers;static uint32_t supported_aead_ciphers; +static uint32_t supported_hash_ciphers;struct l_cipher {int type;
@@ -103,6 +104,11 @@ struct l_aead_cipher {int decrypt_sk; }; +struct l_hash_cipher { +int type; +int encrypt_sk; +}; +static int create_alg (const char *alg_type,const char *alg_name,const void *key,size_t key_length,size_t tag_length) {
@@ -248,6 +254,42 @@ error_free:return NULL ; } +static const char *hash_cipher_type_to_name (enum l_hash_cipher_type type) +{ +switch (type) { +case L_HASH_CIPHER_AES_CMAC : +return "cmac(aes)" ; + } + +return NULL ; +} + +LIB_EXPORT struct l_hash_cipher *l_hash_cipher_new(enum l_hash_cipher_type type, +const void *key, +size_t key_length) +{ +struct l_hash_cipher *cipher; +const char *uninitialized_var (alg_name ); + +if (unlikely (!key)) +return NULL ; + +if (type !=L_HASH_CIPHER_AES_CMAC ) +return NULL ; + + cipher = l_new(struct l_hash_cipher, 1); + cipher->type = type; + alg_name =hash_cipher_type_to_name (type); + + cipher->encrypt_sk =create_alg ("hash" , alg_name, key, key_length, +0 ); +if (cipher->encrypt_sk >=0 ) +return cipher; + +l_free (cipher); +return NULL ; +} + LIB_EXPORT void l_cipher_free(struct l_cipher *cipher) {if (unlikely (!cipher))
@@ -270,6 +312,16 @@ LIB_EXPORT void l_aead_cipher_free(struct l_aead_cipher *cipher)l_free (cipher); } +LIB_EXPORT void l_hash_cipher_free(struct l_hash_cipher *cipher) +{ +if (unlikely (!cipher)) +return ; + +close (cipher->encrypt_sk); + +l_free (cipher); +} + static ssize_t operate_cipher(int sk, __u32 operation, const void *in, size_t in_len, const void *ad, size_t ad_len,
@@ -610,6 +662,20 @@ LIB_EXPORT bool l_aead_cipher_decrypt(struct l_aead_cipher *cipher, (ssize_t )out_len; } +LIB_EXPORT bool l_hash_cipher_encrypt(struct l_hash_cipher *cipher, +const void *in,size_t in_len, +void *out,size_t out_len) +{ +if (unlikely (!cipher)) +return false; + +if (unlikely (!in) ||unlikely (!out)) +return false; + +return operate_cipher (cipher->encrypt_sk,ALG_OP_ENCRYPT , in, in_len, +NULL ,0 ,NULL ,0 , out, out_len) >=0 ; +} +static void init_supported () {static bool initialized = false;
@@ -617,6 +683,7 @@ static void init_supported()int sk;enum l_cipher_type c;enum l_aead_cipher_type a; +enum l_hash_cipher_type h;if (likely (initialized))return ;
@@ -651,6 +718,17 @@ static void init_supported() supported_aead_ciphers |=1 << a; } +strcpy ((char *) salg.salg_type,"hash" ); + +for (h =L_HASH_CIPHER_AES_CMAC ; h <=L_HASH_CIPHER_AES_CMAC ; h++) { +strcpy ((char *) salg.salg_name,hash_cipher_type_to_name (h)); + +if (bind (sk, (struct sockaddr *) &salg,sizeof (salg)) <0 ) +continue ; + + supported_hash_ciphers |=1 << h; + } +close (sk); }
@@ -673,3 +751,13 @@ LIB_EXPORT bool l_aead_cipher_is_supported(enum l_aead_cipher_type type)return supported_aead_ciphers & (1 << type); } + +LIB_EXPORT bool l_hash_cipher_is_supported(enum l_hash_cipher_type type) +{ +if (type !=L_HASH_CIPHER_AES_CMAC ) +return false; + +init_supported (); + +return supported_hash_ciphers & (1 << type); +}
ell/cipher.h +16 -0
@@ -84,8 +84,24 @@ bool l_aead_cipher_decrypt(struct l_aead_cipher *cipher, const void *nonce, size_t nonce_len, void *out, size_t out_len); +struct l_hash_cipher ; + +enum l_hash_cipher_type { +L_HASH_CIPHER_AES_CMAC =0 , +}; + +struct l_hash_cipher *l_hash_cipher_new (enum l_hash_cipher_type type, +const void *key,size_t key_length); + +void l_hash_cipher_free (struct l_hash_cipher *cipher); + +bool l_hash_cipher_encrypt (struct l_hash_cipher *cipher, +const void *in,size_t len, +void *out,size_t out_len); +bool l_cipher_is_supported (enum l_cipher_type type);bool l_aead_cipher_is_supported (enum l_aead_cipher_type type); +bool l_hash_cipher_is_supported (enum l_hash_cipher_type type); #ifdef __cplusplus }
unit/test-cipher.c +74 -0
85 lines not on this page · raw message
Signature · 1 line
2.14.5
Hi Brian,
Quoted 8 lines · Brian Gix
The algorythm is supported in the kernel, and it is used heavily by Bluetooth Mesh, and is the one Mesh required algorythm missing from ELL.
--- ell/cipher.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ell/cipher.h | 16 ++++++++++ unit/test-cipher.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+)
Please be aware of our patch submission guidelines found in HACKING. E.g. the unit test should be in a separate commit.
Have you checked whether l_checksum_new_cmac_aes() satisfies your needs?
Regards,
-Denis
Gix
Hi Denis,
Quoted 13 lines · Denis Kenzior
Hi Brian,
Quoted 8 lines · Brian Gix
The algorythm is supported in the kernel, and it is used heavily by Bluetooth Mesh, and is the one Mesh required algorythm missing from ELL.
--- ell/cipher.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ell/cipher.h | 16 ++++++++++ unit/test-cipher.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+)
Quoted 3 lines
Please be aware of our patch submission guidelines found in HACKING. E.g. the unit test should be in a separate commit.
Have you checked whether
l_checksum_new_cmac_aes()satisfies your needs?
I didn’t see that. I will check it out, and if it works, I will withdraw my patch altogether. If it does not work, I will resubmit as a patch-set.
Quoted 3 lines
Regards,
-Denis
Gix
Hi Denis,
It does work, Thanks.
I will probably do one patch anyway, to add a couple tests to test-checksum.c, because currently a unit test for l_checksum_new_cmac_aes() is conspicuous in it's absence.
Quoted 31 lines · Brian
Hi Denis,
Quoted 13 lines · Denis Kenzior
Hi Brian,
Quoted 8 lines · Brian Gix
The algorythm is supported in the kernel, and it is used heavily by Bluetooth Mesh, and is the one Mesh required algorythm missing from ELL.
--- ell/cipher.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ell/cipher.h | 16 ++++++++++ unit/test-cipher.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+)Quoted 4 lines
Please be aware of our patch submission guidelines found in HACKING. E.g. the unit test should be in a separate commit.
Have you checked whether
l_checksum_new_cmac_aes()satisfies your needs?I didn’t see that. I will check it out, and if it works, I will withdraw my patch altogether. If it does not work, I will resubmit as a patch-set.
Quoted 3 lines
Regards,
-Denis_______________________________________________
ell mailing list
ell(a)lists.01.org
https://lists.01.org/mailman/listinfo/ell
Hi Brian,
Quoted 2 lines · Brian
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The algorythm is supported in the kernel, and it is used heavily by Bluetooth Mesh, and is the one Mesh required algorythm missing from ELL.
Is this about mesh_crypto_aes_ccm_encrypt and mesh_crypto_aes_ccm_decrypt functions in mesh/crypto.c?
If so, they can be implemented with l_aead_cipher_* API, without any changes to ELL, see below.
There is a slight problem, though - this works only on newer kernels (IIRC, 4.9+), and some vendors (particularly Freescale i.MX6) do not provide them :(
What's worse, my experiments show what the kernel does *not* report an error while bind()ing the algo socket, but the results are wrong :(
bool mesh_crypto_aes_ccm_encrypt(const uint8_t nonce[NONCE_LEN],
const uint8_t key[KEY_LEN],
const uint8_t *aad, uint16_t aad_len, const uint8_t *msg, uint16_t msg_len, uint8_t *out_msg,
void *out_mic, size_t mic_size)
{
bool result;
struct l_aead_cipher *cipher = l_aead_cipher_new(L_AEAD_CIPHER_AES_CCM,
&key[0], KEY_LEN, mic_size);
if (!cipher)
return false;
if (!out_msg)
return false;
result = l_aead_cipher_encrypt(cipher, (void *)msg, msg_len,
aad, aad_len, &nonce[0], NONCE_LEN,
(void *)out_msg, msg_len + mic_size);
if (out_mic) {
switch (mic_size) {
case 4:
*(uint32_t *)out_mic = l_get_be32(out_msg + msg_len);
break;
case 8:
*(uint64_t *)out_mic = l_get_be64(out_msg + msg_len);
break;
default:
/* Unsupported MIC size */
return false;
}
}
l_aead_cipher_free(cipher);
return result;
}bool mesh_crypto_aes_ccm_decrypt(const uint8_t nonce[13], const uint8_t key[16],
const uint8_t *aad, uint16_t aad_len, const uint8_t *enc_msg, uint16_t enc_msg_len, uint8_t *out_msg,
void *out_mic, size_t mic_size)
{
bool result;
struct l_aead_cipher *cipher = l_aead_cipher_new(L_AEAD_CIPHER_AES_CCM,
&key[0], KEY_LEN, mic_size);
if (!cipher)
return false;
result = l_aead_cipher_decrypt(cipher, (void *)enc_msg, enc_msg_len,
aad, aad_len, &nonce[0], NONCE_LEN,
(void *)out_msg, enc_msg_len - mic_size);
if (out_mic) {
switch (mic_size) {
case 4:
*(uint32_t *)out_mic = l_get_be32(out_msg +
enc_msg_len - mic_size);
break;
case 8:
*(uint64_t *)out_mic = l_get_be64(out_msg +
enc_msg_len - mic_size);
break;
default:
/* Unsupported MIC size */
return false;
}
}
l_aead_cipher_free(cipher);
return result;
}Signature · 3 lines
Michał Lowas-Rzechonek <[email protected]> Silvair http://silvair.com Jasnogórska 44, 31-358 Krakow, POLAND
Gix
Hi Michał,
Quoted 8 lines · Michał Lowas-Rzechonek
Hi Brian,
Quoted 2 lines · Brian
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The algorythm is supported in the kernel, and it is used heavily by Bluetooth Mesh, and is the one Mesh required algorythm missing from ELL.
Is this about
mesh_crypto_aes_ccm_encryptandmesh_crypto_aes_ccm_decryptfunctions inmesh/crypto.c?
The code you copy pasted below *is* the usage of AES_CCM that we use in mesh, but it is *not* the topic of the patch I posted here to ELL yesterday. AES-CMAC is the algorythm we use in Mesh to generate all of the various Keys and IDs from master Net and App keys.... It is a simple one-directional hashing function, and as I also learned yesterday, is already supported in ELLs checksum.c code.
Quoted 7 lines
If so, they can be implemented with l_aead_cipher_* API, without any changes to ELL, see below.
There is a slight problem, though - this works only on newer kernels (IIRC, 4.9+), and some vendors (particularly Freescale i.MX6) do not provide them :(
This is definitely a question worth answering. We are aware that pre-4.9 kernels did not correctly support AES_CCM, so switching the mesh daemon's crypto to pure ELL supported kernel based encryption and decryption will mean that the daemon is not supported on very old kernels.
As far as Freescale platforms go, I do not know how to answer that question. At some point we do need to move on from older platforms so that the rest are not "held back". But I do not know if that time is yet now.
I would really like to get Marcel's opinion on this.
Quoted 82 lines
What's worse, my experiments show what the kernel does *not* report an error while bind()ing the algo socket, but the results are wrong :(
bool mesh_crypto_aes_ccm_encrypt(const
uint8_tnonce[NONCE_LEN],
constuint8_tkey[KEY_LEN],
constuint8_t*aad,uint16_taad_len, constuint8_t*msg,uint16_tmsg_len,uint8_t*out_msg,
void*out_mic,size_tmic_size){ bool result; struct l_aead_cipher *cipher = l_aead_cipher_new(L_AEAD_CIPHER_AES_CCM, &key[0], KEY_LEN, mic_size); if (!cipher) return false; if (!out_msg) return false; result = l_aead_cipher_encrypt(cipher, (void *)msg, msg_len, aad, aad_len, &nonce[0], NONCE_LEN, (void *)out_msg, msg_len + mic_size); if (out_mic) { switch (mic_size) { case 4: *(uint32_t *)out_mic = l_get_be32(out_msg + msg_len); break; case 8: *(uint64_t *)out_mic = l_get_be64(out_msg + msg_len); break; default: /* Unsupported MIC size */ return false; } } l_aead_cipher_free(cipher); return result; }bool mesh_crypto_aes_ccm_decrypt(const
uint8_tnonce[13], constuint8_tkey[16],
constuint8_t*aad,uint16_taad_len, constuint8_t*enc_msg,uint16_tenc_msg_len,uint8_t*out_msg,
void*out_mic,size_tmic_size){ bool result; struct l_aead_cipher *cipher = l_aead_cipher_new(L_AEAD_CIPHER_AES_CCM, &key[0], KEY_LEN, mic_size); if (!cipher) return false; result = l_aead_cipher_decrypt(cipher, (void *)enc_msg, enc_msg_len, aad, aad_len, &nonce[0], NONCE_LEN, (void *)out_msg, enc_msg_len - mic_size); if (out_mic) { switch (mic_size) { case 4: *(uint32_t *)out_mic = l_get_be32(out_msg + enc_msg_len - mic_size); break; case 8: *(uint64_t *)out_mic = l_get_be64(out_msg + enc_msg_len - mic_size); break; default: /* Unsupported MIC size */ return false; } } l_aead_cipher_free(cipher); return result; }
Hi Brian, Denis,
Quoted 4 lines · Brian
Quoted 2 lines
Is this about
mesh_crypto_aes_ccm_encryptandmesh_crypto_aes_ccm_decryptfunctions inmesh/crypto.c?The code you copy pasted below *is* the usage of
AES_CCMthat we use in mesh,
Um, it's not - mesh_crypto_aes_ccm_* functions seem to implement AES_CCM on top of ECB, in user space. As Denis mentioned, this is somewhat inefficient, but at least it works on older kernels.
I was thinking about submitting a patch to change that, but then I'd be shooting myself in the foot, because my target platform runs kernel 4.4 if I recall correctly ;)
Quoted 3 lines
but it is *not* the topic of the patch I posted here to ELL yesterday. AES-CMAC is the algorithm we use in Mesh to generate all of the various Keys and IDs from master Net and App keys....
Ah, right, it's the K* family of functions. Sorry, I confused CCM and CMAC modes.
regards
Signature · 3 lines
Michał Lowas-Rzechonek <[email protected]> Silvair http://silvair.com Jasnogórska 44, 31-358 Krakow, POLAND
Gix
Hi Michal,
Quoted 11 lines · michal.lowas-rzechonek(a)silvair.com
Hi Brian, Denis,
Quoted 4 lines · Brian
Quoted 2 lines
Is this about
mesh_crypto_aes_ccm_encryptandmesh_crypto_aes_ccm_decryptfunctions inmesh/crypto.c?The code you copy pasted below *is* the usage of
AES_CCMthat we use in mesh,Um, it's not - mesh_crypto_aes_ccm_* functions seem to implement
AES_CCMon top of ECB, in user space. As Denis mentioned, this is somewhat inefficient, but at least it works on older kernels.
Yes, I understand now... You wrote the code snippet, that looked an awful lot like the patch I was in the middle of writing for mesh_crypto_aes_ccm_*....
my best guess right now is that we will probably decide to go ahead and patch mesh such that it assumes an up- to-date kernel version, and a working underlying architecture.
It will then be the responsibility of the vendor (you guys) to patch mesh such that it continues to work on your older kernels and perhaps architectures. That way future kernels and platforms are not perpetually "held back" to support kernels that should be obsoleted or fixed.
Quoted 5 lines
I was thinking about submitting a patch to change that, but then I'd be shooting myself in the foot, because my target platform runs kernel 4.4 if I recall correctly ;)
Quoted 8 lines
Quoted 3 lines
but it is *not* the topic of the patch I posted here to ELL yesterday. AES-CMAC is the algorithm we use in Mesh to generate all of the various Keys and IDs from master Net and App keys....
Ah, right, it's the K* family of functions. Sorry, I confused CCM and CMAC modes.
regards
Best Reagrds,
Brian
Hi Michał,
Quoted 2 lines
Is this about
mesh_crypto_aes_ccm_encryptandmesh_crypto_aes_ccm_decryptfunctions inmesh/crypto.c?
No, this is different. But *yikes*. BlueZ implements AEAD cipher in terms of ecb(aes)? That is highly inefficient due to syscall overhead.
Quoted 3 lines
If so, they can be implemented with l_aead_cipher_* API, without any changes to ELL, see below.
That would be much better, yes.
Quoted 7 lines
There is a slight problem, though - this works only on newer kernels (IIRC, 4.9+), and some vendors (particularly Freescale i.MX6) do not provide them :(
What's worse, my experiments show what the kernel does *not* report an error while bind()ing the algo socket, but the results are wrong :(
I think there was a bug in AEAD ciphers, the reported length from one of the operations was incorrect. I believe Mat fixed this and ell deals with this correctly. See 08be47564b3c49404e5cb6061c0ede94b0a9e783.
But still, 4.9 is a freaking old kernel. Worst case have the vendor port the fixed aead implementation into their tree.
If this isn't available, you can always hack in a fallback in bluez to keep the same ecb(aes) behavior, but that's just painful :)
Regards,
-Denis
Gix
ELL building broken for 32bit systems
As part of my Bluetooth Mesh change-over from user-space crypto to ELL provided cipher and checksum routines, I have been building on all the platforms I have available to me, including Fedora-30 running on 32bit i686 architecture.
Here are the issues I encountered:
There is an unchecked build dependancy on "xxd", which appears to be provided by the vim-common package. This probably affects all platforms, but my 32-bit F30 installation is deliberately kept "minimal", so that is where it showed up.
After installing vim-common, there is a build error that is unique to the 32bit F30 (it works fine on 64 bit systems). When doing a full build (and when doing a build of *only* unit/test-cipher) I get the following error when building ell/genl.c:
[ell]$ make -k unit/test-cipher
CC ell/genl.lo
In file included from /usr/include/string.h:494,
from ell/util.h:26,
from ell/genl.c:32:In function ‘strncpy’,
inlined from ‘family_add_mcast’ at ell/genl.c:240:2, inlined from ‘family_add_mcast.isra.0’ at ell/genl.c:224:13:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘strncpy’,
inlined from ‘get_family_callback’ at ell/genl.c:1049:4:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘strncpy’,
inlined from ‘family_alloc’ at ell/genl.c:164:2:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:1780: ell/genl.lo] Error 1
make: Target 'unit/test-cipher' not remade because of errors.
Gix
Re: ELL building broken for 32bit systems
Quoted 8 lines · Brian
As part of my Bluetooth Mesh change-over from user-space crypto to ELL
provided cipher and checksum routines, I have been building on all the
platforms I have available to me, including Fedora-30 running on 32bit
i686 architecture.
Quoted 6 lines
Here are the issues I encountered:
There is an unchecked build dependancy on "xxd", which appears to be provided by the vim-common package. This probably affects all platforms, but my 32-bit F30 installation is deliberately kept "minimal", so that is where it showed up.
Actually for this one, xxd is checked for, but it doesn't cause a failure of ./bootstrap-configure, even though it correctly determines that xxd is missing.
Quoted 53 lines
After installing vim-common, there is a build error that is unique to the 32bit F30 (it works fine on 64 bit systems). When doing a full build (and when doing a build of *only* unit/test-cipher) I get the following error when building
ell/genl.c:[ell]$ make -k unit/test-cipher
CC ell/genl.lo
In file included from/usr/include/string.h:494,from ell/util.h:26, from ell/genl.c:32:In function ‘strncpy’,
inlined from ‘family_add_mcast’ atell/genl.c:240:2, inlined from ‘family_add_mcast.isra.0’ atell/genl.c:224:13:/usr/include/bits/string_fortified.h:106:10: error:
‘__builtin_strncpy’
specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~
In function ‘strncpy’,
inlined from ‘get_family_callback’ atell/genl.c:1049:4:/usr/include/bits/string_fortified.h:106:10: error:
‘__builtin_strncpy’
specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~
In function ‘strncpy’,
inlined from ‘family_alloc’ atell/genl.c:164:2:/usr/include/bits/string_fortified.h:106:10: error:
‘__builtin_strncpy’
specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:1780: ell/genl.lo] Error 1
make: Target 'unit/test-cipher' not remade because of errors.
_______________________________________________
ell mailing list
ell(a)lists.01.org
https://lists.01.org/mailman/listinfo/ell
Re: ELL building broken for 32bit systems
In reply to GixHi Brian,
Quoted 3 lines
build (and when doing a build of *only* unit/test-cipher) I get the following error when building
ell/genl.c:
Uhh, no idea why only test-cipher, but okay...
Quoted 30 lines
[ell]$ make -k unit/test-cipher
CC ell/genl.lo
In file included from/usr/include/string.h:494,from ell/util.h:26, from ell/genl.c:32:In function ‘strncpy’,
inlined from ‘family_add_mcast’ atell/genl.c:240:2, inlined from ‘family_add_mcast.isra.0’ atell/genl.c:224:13:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘strncpy’,
inlined from ‘get_family_callback’ atell/genl.c:1049:4:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘strncpy’,
inlined from ‘family_alloc’ atell/genl.c:164:2:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos
Quoted 3 lines
(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What version are you using? Upstream ell doesn't even use strncpy in genl.c anymore.
Regards,
-Denis
Gix
RE: ELL building broken for 32bit systems
Hi Denis,
Quoted 8 lines
Hi Brian,
Quoted 3 lines
build (and when doing a build of *only* unit/test-cipher) I get the following error when building
ell/genl.c:Uhh, no idea why only test-cipher, but okay...
Sorry... I was trying to short-cut my own needs to be able to recommend the running of test-cipher in the README file of Bluetooth mesh to determine if the known "old kernel" AEAD problem existed... But yes, this is an ELL wide problem.
Quoted 35 lines
Quoted 31 lines
[ell]$ make -k unit/test-cipher
CC ell/genl.lo
In file included from/usr/include/string.h:494,from ell/util.h:26, from ell/genl.c:32:In function ‘strncpy’,
inlined from ‘family_add_mcast’ atell/genl.c:240:2, inlined from ‘family_add_mcast.isra.0’ atell/genl.c:224:13:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘strncpy’,
inlined from ‘get_family_callback’ atell/genl.c:1049:4:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bos(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘strncpy’,
inlined from ‘family_alloc’ atell/genl.c:164:2:/usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Werror=stringop- truncation]
106 | return__builtin___strncpy_chk(__dest,__src,__len,__bosQuoted 3 lines
(__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 2 lines
What version are you using? Upstream ell doesn't even use strncpy in
genl.canymore.
This is unmodified Fedora-30 for i686 32-bit. I tried chasing down the nesting rabbit-hole to find exactly where the strncpy's were coming from, and came up empty... I can only assume that some inlined function in string.h resolves to some version of strncpy on 32-bit fedora... perhaps relating to the strlcpy calls.
For what it's worth, this does not appear to be *new* per se... Checking out the first labeled ELL version from Jan-2019 causes the same errors.
I do know that F30 introduced a number of alignment warnings (which are thrown as errors) that did not exist in F29.
Re: ELL building broken for 32bit systems
Hi Brian,
Quoted 4 lines
Quoted 2 lines
What version are you using? Upstream ell doesn't even use strncpy in
genl.canymore.This is unmodified Fedora-30 for i686 32-bit. I tried chasing down the nesting rabbit-hole to find exactly where the strncpy's were coming from, and came up empty... I can only assume that some inlined function in
string.hresolves to some version of strncpy on 32-bit fedora... perhaps relating to the strlcpy calls.
No, I meant what version of ell? The issue comes from gcc9 which is much more strict about checking strncpy use than before. The problem is that we used to use something like:
#define FOO_BUFFER_SIZE
char buf[FOO_BUFFER_SIZE];
strncpy(buf, some_string, sizeof(buf));
Which would leave the buffer non-null terminated. Not really a concern since all the strings came from the kernel and the chances of things ending up badly were small, but still...
The fix is to either use sizeof(buf) - 1 and null-terminate the string, or just use l_strlcpy.
Upstream ell is down to about 4 occurrences of strncpy, none of them in genl. So if you are having this problem with some previous release of ell, then you should simply disable this warning.
Regards,
-Denis
Gix
Re: ELL building broken for 32bit systems
Hi Denis,
Quoted 7 lines · Denis Kenzior
No, I meant what version of ell? The issue comes from gcc9 which
Quoted 1 line
Quoted 1 line
is
much more strict about checking strncpy use than before. The problem is
that we used to use something like:
Damnit, that is my bad. My VM version of the git repo was wedged, and stuck on an early Apirl-2019 version of ELL. So, I am no longer getting the build warning=error for genl.c as of the (now) tip:
Quoted 1 line
commit
21306874a2318eb17cdd23ec1cb0ed1a193d5971(HEAD -> master,
origin/master, origin/HEAD)
Quoted 2 lines
Author: Tim Kourt <[email protected]> Date: Thu May 30 13:20:48 2019 -0700
There *are* now three unit test assertions happening which I didn't notice before, although they are in an area that doesn't affect me personally.
These failures happen on both 64 and 32 bit Fedora 30:
[ell]$ unit/test-pem
TEST: pem/invalid header/test 1
TEST: pem/invalid header/test 2
TEST: pem/empty
TEST: pem/empty label
TEST: pem/v1 MD5AndDES encrypted Private Key
test-pem: unit/test-pem.c:111: test_encrypted_pkey: Assertion `pkey1' failed.
Aborted (core dumped)
[ell]$ unit/test-tls
Running sysctl kernel.keys.maxkeys=2000 is recommended
TEST: TLS 1.0 PRF
TEST: TLS 1.2 PRF with SHA256
TEST: TLS 1.2 PRF with SHA384
TEST: TLS 1.2 PRF with SHA512
TEST: Certificate chains
TEST: TLS connection no auth
test-tls: unit/test-tls.c:550: test_tls_with_ver: Assertion `auth_ok' failed.
Aborted (core dumped)
[ell]$ unit/test-key
TEST: unsupported
TEST: user key
TEST: Diffie-Hellman 1
TEST: Diffie-Hellman 2
TEST: Diffie-Hellman 3
TEST: simple keyring
TEST: trusted keyring
TEST: trust chain
TEST: key crypto
test-key: unit/test-key.c:572: test_key_crypto: Assertion `privkey' failed.
Aborted (core dumped)