ethdev: fix 32-bit build with GCC-13

Message ID 20231101071554.1316358-1-ruifeng.wang@arm.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: fix 32-bit build with GCC-13 |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Ruifeng Wang Nov. 1, 2023, 7:15 a.m. UTC
  aarch32 build with gcc-13.0.1 generated following warning:

In function 'memcpy',
    inlined from 'rte_memcpy' at ../lib/eal/arm/include/rte_memcpy_32.h:296:9,
    inlined from 'rte_flow_conv_action_conf' at ../lib/ethdev/rte_flow.c:726:20,
    inlined from 'rte_flow_conv_actions' at ../lib/ethdev/rte_flow.c:936:10:
warning: '__builtin_memcpy' specified bound 4294967264 exceeds maximum object size 2147483647 [-Wstringop-overflow=]

The issue is due to possible wrapping in unsigned arithmetic.
The 'size' can be 0. 'off' is 32. When 'tmp' is equal to (unsigned)-32,
the copy length is more than half the address space. Hence the warning.

Casted variables to 64-bit to avoid wrapping.

Fixes: 063911ee1df4 ("ethdev: add flow API object converter")
Cc: adrien.mazarguil@6wind.com
Cc: stable@dpdk.org

Reported-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
 lib/ethdev/rte_flow.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Ori Kam Nov. 1, 2023, 8:12 a.m. UTC | #1
Hi

> -----Original Message-----
> From: Ruifeng Wang <ruifeng.wang@arm.com>
> Sent: Wednesday, November 1, 2023 9:16 AM
> 
> aarch32 build with gcc-13.0.1 generated following warning:
> 
> In function 'memcpy',
>     inlined from 'rte_memcpy' at
> ../lib/eal/arm/include/rte_memcpy_32.h:296:9,
>     inlined from 'rte_flow_conv_action_conf' at ../lib/ethdev/rte_flow.c:726:20,
>     inlined from 'rte_flow_conv_actions' at ../lib/ethdev/rte_flow.c:936:10:
> warning: '__builtin_memcpy' specified bound 4294967264 exceeds maximum
> object size 2147483647 [-Wstringop-overflow=]
> 
> The issue is due to possible wrapping in unsigned arithmetic.
> The 'size' can be 0. 'off' is 32. When 'tmp' is equal to (unsigned)-32,
> the copy length is more than half the address space. Hence the warning.
> 
> Casted variables to 64-bit to avoid wrapping.
> 
> Fixes: 063911ee1df4 ("ethdev: add flow API object converter")
> Cc: adrien.mazarguil@6wind.com
> Cc: stable@dpdk.org
> 
> Reported-by: Luca Boccassi <bluca@debian.org>
> Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
> ---
>  lib/ethdev/rte_flow.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
> index 3a67f1aaba..2a5a057195 100644
> --- a/lib/ethdev/rte_flow.c
> +++ b/lib/ethdev/rte_flow.c
> @@ -722,7 +722,7 @@ rte_flow_conv_action_conf(void *buf, const size_t
> size,
>  		if (src.rss->key_len && src.rss->key) {
>  			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
>  			tmp = sizeof(*src.rss->key) * src.rss->key_len;
> -			if (size >= off + tmp)
> +			if (size >= (uint64_t)off + (uint64_t)tmp)
>  				dst.rss->key = rte_memcpy
>  					((void *)((uintptr_t)dst.rss + off),
>  					 src.rss->key, tmp);
> @@ -731,7 +731,7 @@ rte_flow_conv_action_conf(void *buf, const size_t
> size,
>  		if (src.rss->queue_num) {
>  			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
>  			tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
> -			if (size >= off + tmp)
> +			if (size >= (uint64_t)off + (uint64_t)tmp)
>  				dst.rss->queue = rte_memcpy
>  					((void *)((uintptr_t)dst.rss + off),
>  					 src.rss->queue, tmp);
> --
> 2.25.1

Acked-by: Ori Kam <orika@nvidia.com>
Best,
Ori
  
Ferruh Yigit Nov. 1, 2023, 4:57 p.m. UTC | #2
On 11/1/2023 8:12 AM, Ori Kam wrote:
> Hi
> 
>> -----Original Message-----
>> From: Ruifeng Wang <ruifeng.wang@arm.com>
>> Sent: Wednesday, November 1, 2023 9:16 AM
>>
>> aarch32 build with gcc-13.0.1 generated following warning:
>>
>> In function 'memcpy',
>>     inlined from 'rte_memcpy' at
>> ../lib/eal/arm/include/rte_memcpy_32.h:296:9,
>>     inlined from 'rte_flow_conv_action_conf' at ../lib/ethdev/rte_flow.c:726:20,
>>     inlined from 'rte_flow_conv_actions' at ../lib/ethdev/rte_flow.c:936:10:
>> warning: '__builtin_memcpy' specified bound 4294967264 exceeds maximum
>> object size 2147483647 [-Wstringop-overflow=]
>>
>> The issue is due to possible wrapping in unsigned arithmetic.
>> The 'size' can be 0. 'off' is 32. When 'tmp' is equal to (unsigned)-32,
>> the copy length is more than half the address space. Hence the warning.
>>
>> Casted variables to 64-bit to avoid wrapping.
>>
>> Fixes: 063911ee1df4 ("ethdev: add flow API object converter")
>> Cc: stable@dpdk.org
>>
>> Reported-by: Luca Boccassi <bluca@debian.org>
>> Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
>>>
> Acked-by: Ori Kam <orika@nvidia.com>
> 

Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 3a67f1aaba..2a5a057195 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -722,7 +722,7 @@  rte_flow_conv_action_conf(void *buf, const size_t size,
 		if (src.rss->key_len && src.rss->key) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
 			tmp = sizeof(*src.rss->key) * src.rss->key_len;
-			if (size >= off + tmp)
+			if (size >= (uint64_t)off + (uint64_t)tmp)
 				dst.rss->key = rte_memcpy
 					((void *)((uintptr_t)dst.rss + off),
 					 src.rss->key, tmp);
@@ -731,7 +731,7 @@  rte_flow_conv_action_conf(void *buf, const size_t size,
 		if (src.rss->queue_num) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
 			tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
-			if (size >= off + tmp)
+			if (size >= (uint64_t)off + (uint64_t)tmp)
 				dst.rss->queue = rte_memcpy
 					((void *)((uintptr_t)dst.rss + off),
 					 src.rss->queue, tmp);