crypto/openssl: fix warning on copy length
PATCH 1/1 crypto/openssl: fix warning on copy length
When building with gcc 11.2.0, the compiler warns as follows:
In function 'memcpy',
inlined from 'openssl_set_session_auth_parameters' at ../drivers/crypto/openssl/rte_openssl_pmd.c:699:3,
inlined from 'openssl_set_session_parameters' at ../drivers/crypto/openssl/rte_openssl_pmd.c:826:9:/usr/include/aarch64-linux-gnu/bits/string_fortified.h:29:10: warning: '__builtin_memcpy' forming offset [4, 8] is out of the bounds [0, 4] [-Warray-bounds]
Fixed the warning by copying up to string size.
--- drivers/crypto/openssl/rte_openssl_pmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/openssl/rte_openssl_pmd.c +1 -1
@@ -696,7 +696,7 @@ openssl_set_session_auth_parameters(struct openssl_session *sess, algo =digest_name_get (xform->auth.algo);if (!algo)return -EINVAL ; -rte_memcpy (algo_name, algo, (sizeof (algo)+1 )); +rte_memcpy (algo_name, algo,strlen (algo) +1 ); mac =EVP_MAC_fetch (NULL ,"HMAC" ,NULL ); sess->auth.hmac.ctx =EVP_MAC_CTX_new (mac);
Signature · 1 line
2.25.1
Quoted 24 lines · Ruifeng Wang
When building with gcc 11.2.0, the compiler warns as follows:
In function 'memcpy',
inlined from 'openssl_set_session_auth_parameters' at../drivers/crypto/openssl/rte_openssl_pmd.c:699:3,
inlined from 'openssl_set_session_parameters' at../drivers/crypto/openssl/rte_openssl_pmd.c:826:9:/usr/include/aarch64-linux-gnu/bits/string_fortified.h:29:10: warning: '__builtin_memcpy' forming offset [4, 8] is out of the bounds [0, 4] [-Warray-bounds]Fixed the warning by copying up to string size.
Fixes 75adf1eae44f ("crypto/openssl: update HMAC routine with 3.0 EVP API")Signed-off-by Ruifeng Wang <[email protected]>Reviewed-by Feifei Wang <[email protected]>--- drivers/crypto/openssl/rte_openssl_pmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/openssl/rte_openssl_pmd.c +0
-0
drivers/crypto/openssl/rte_openssl_pmd.c openssl_set_session_auth_parameters(struct openssl_session *sess, · line 699
Quoted 5 lines
drivers/crypto/openssl/rte_openssl_pmd.c +1
-1@@ -696,7 +696,7 @@ openssl_set_session_auth_parameters(struct openssl_session *sess, algo =digest_name_get (xform->auth.algo);if (!algo)return -EINVAL ; -rte_memcpy (algo_name, algo, (sizeof (algo)+1 )); +rte_memcpy (algo_name, algo,strlen (algo) +1 );
Why is there a need for copying such a string to a local storage?
If it is really needed, we are dealing with strings, so I suggest:strlcpy(algo_name, algo, sizeof(algo_name));
Signature · 1 line
David Marchand
Quoted 33 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, January 6, 2023 6:27 PM
To: Kai Ji <[email protected]>; Ruifeng Wang <[email protected]>
Cc: Fan Zhang <[email protected]>; Akhil Goyal <[email protected]>; [email protected]; nd <[email protected]>; [email protected]; Feifei Wang <[email protected]>
Subject: Re: [PATCH]crypto/openssl: fix warning on copy lengthQuoted 4 lines · Ruifeng Wang
When building with gcc 11.2.0, the compiler warns as follows:
In function 'memcpy',
inlined from 'openssl_set_session_auth_parameters'at
../drivers/crypto/openssl/rte_openssl_pmd.c:699:3,Quoted 1 line
inlined from '
openssl_set_session_parameters'at
../drivers/crypto/openssl/rte_openssl_pmd.c:826:9:Quoted 1 line
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:29:10: warning:'
__builtin_memcpy' forming offset [4, 8] is out of the bounds [0, 4] [-Warray-bounds]Quoted 7 lines
Fixed the warning by copying up to string size.
Fixes 75adf1eae44f ("crypto/openssl: update HMAC routine with 3.0 EVP API")Review
Quoted 7 lines
Signed-off-by Ruifeng Wang <[email protected]>Reviewed-by Feifei Wang <[email protected]>--- drivers/crypto/openssl/rte_openssl_pmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/crypto/openssl/rte_openssl_pmd.c
Quoted 11 lines
drivers/crypto/openssl/rte_openssl_pmd.c openssl_set_session_auth_parameters(struct openssl_session *sess, · line 699
Quoted 9 lines
index
05449b6e98..8458ad487a100644drivers/crypto/openssl/rte_openssl_pmd.c +1
-1@@ -696,7 +696,7 @@ openssl_set_session_auth_parameters(struct openssl_session *sess, algo =digest_name_get (xform->auth.algo);if (!algo)return -EINVAL ; -rte_memcpy (algo_name, algo, (sizeof (algo)+1 )); +rte_memcpy (algo_name, algo,strlen (algo) +1 );Why is there a need for copying such a string to a local storage?
From OpenSSL document, I can see OSSL_PARAM_construct_utf8_string() takes a buffer as input. But I'm not sure if a const is acceptable.
I would keep the fix simple for backport. Removing copy is an improvement that can be done by someone who has more knowledge of OpenSSL library.
Quoted 3 lines
If it is really needed, we are dealing with strings, so I suggest:
strlcpy(algo_name, algo, sizeof(algo_name));
Thanks for the suggestion. Will update in v2.
Regards,
Ruifeng
Quoted 4 lines
--
David Marchand
PATCH v2 1/1 crypto/openssl: fix warning on copy length
In reply to Ruifeng WangWhen building with gcc 11.2.0, the compiler warns as follows:
In function 'memcpy',
inlined from 'openssl_set_session_auth_parameters' at ../drivers/crypto/openssl/rte_openssl_pmd.c:699:3,
inlined from 'openssl_set_session_parameters' at ../drivers/crypto/openssl/rte_openssl_pmd.c:826:9:/usr/include/aarch64-linux-gnu/bits/string_fortified.h:29:10: warning: '__builtin_memcpy' forming offset [4, 8] is out of the bounds [0, 4] [-Warray-bounds]
Fixed the warning by copying up to string / buffer size.
--- drivers/crypto/openssl/rte_openssl_pmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/openssl/rte_openssl_pmd.c +1 -1
@@ -696,7 +696,7 @@ openssl_set_session_auth_parameters(struct openssl_session *sess, algo =digest_name_get (xform->auth.algo);if (!algo)return -EINVAL ; -rte_memcpy (algo_name, algo, (sizeof (algo)+1 )); +strlcpy (algo_name, algo,sizeof (algo_name)); mac =EVP_MAC_fetch (NULL ,"HMAC" ,NULL ); sess->auth.hmac.ctx =EVP_MAC_CTX_new (mac);
Signature · 1 line
2.25.1
Akhil Goyal
AppliedQuoted 10 lines
When building with gcc 11.2.0, the compiler warns as follows:
In function 'memcpy',
inlined from 'openssl_set_session_auth_parameters' at../drivers/crypto/openssl/rte_openssl_pmd.c:699:3,
inlined from 'openssl_set_session_parameters' at../drivers/crypto/openssl/rte_openssl_pmd.c:826:9:/usr/include/aarch64-linux-gnu/bits/string_fortified.h:29:10: warning:
'__builtin_memcpy' forming offset [4, 8] is out of the bounds [0, 4] [-Warray- bounds]
Quoted 8 lines
Fixed the warning by copying up to string / buffer size.
Fixes 75adf1eae44f ("crypto/openssl: update HMAC routine with 3.0 EVP API")Signed-off-by Ruifeng Wang <[email protected]>Reviewed-by Feifei Wang <[email protected]>
Applied to dpdk-next-crypto
Thanks.