net/i40e: fix build for 32-bit

Message ID 20211029103701.4094508-1-ferruh.yigit@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series net/i40e: fix build for 32-bit |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
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-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Ferruh Yigit Oct. 29, 2021, 10:37 a.m. UTC
  Got error with: gcc 11.2.1 "cc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)"

Build error:
In function ‘i40e_flow_parse_fdir_pattern’,
    inlined from ‘i40e_flow_parse_fdir_filter’
    at ../drivers/net/i40e/i40e_flow.c:3274:8:
../drivers/net/i40e/i40e_flow.c:3052:69:
    error: writing 1 byte into a region of size 0
    [-Werror=stringop-overflow=]
 3052 |                         filter->input.flow_ext.flexbytes[j] =
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
 3053 |                                 raw_spec->pattern[i];
      |                                 ~~~~~~~~~~~~~~~~~~~~
In file included from ../drivers/net/i40e/i40e_flow.c:25:
  ../drivers/net/i40e/i40e_flow.c:
  In function ‘i40e_flow_parse_fdir_filter’:
  ../drivers/net/i40e/i40e_ethdev.h:638:17:
  note: at offset 16 into destination object ‘flexbytes’ of size 16
  638 |         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
      |                 ^~~~~~~~~

Fixing by adding range checks.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Qi Z Zhang <qi.z.zhang@intel.com>

Not sure why only 32-bit is causing this error, or if the overflow
practically can occurs.

./devtools/test-meson-builds.sh is not catching the warning because of
'--buildtype=debugoptimized'.

I can reproduce in my environment as following:
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig meson --werror -Dc_args=-m32
-Dc_link_args=-m32 build && ninja -C build
---
 drivers/net/i40e/i40e_flow.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Qi Zhang Nov. 1, 2021, 1:15 a.m. UTC | #1
> -----Original Message-----
> From: Yigit, Ferruh <ferruh.yigit@intel.com>
> Sent: Friday, October 29, 2021 6:37 PM
> To: Xing, Beilei <beilei.xing@intel.com>
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; dev@dpdk.org; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Subject: [PATCH] net/i40e: fix build for 32-bit
> 
> Got error with: gcc 11.2.1 "cc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)"
> 
> Build error:
> In function ‘i40e_flow_parse_fdir_pattern’,
>     inlined from ‘i40e_flow_parse_fdir_filter’
>     at ../drivers/net/i40e/i40e_flow.c:3274:8:
> ../drivers/net/i40e/i40e_flow.c:3052:69:
>     error: writing 1 byte into a region of size 0
>     [-Werror=stringop-overflow=]
>  3052 |                         filter->input.flow_ext.flexbytes[j] =
>       |
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
>  3053 |                                 raw_spec->pattern[i];
>       |                                 ~~~~~~~~~~~~~~~~~~~~
> In file included from ../drivers/net/i40e/i40e_flow.c:25:
>   ../drivers/net/i40e/i40e_flow.c:
>   In function ‘i40e_flow_parse_fdir_filter’:
>   ../drivers/net/i40e/i40e_ethdev.h:638:17:
>   note: at offset 16 into destination object ‘flexbytes’ of size 16
>   638 |         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
>       |                 ^~~~~~~~~
> 
> Fixing by adding range checks.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>

Applied to dpdk-next-net-intel after added below fixline and Cc stable.
Fixes: 6ced3dd72f5f ("net/i40e: support flexible payload parsing for FDIR")

Thanks
Qi
  

Patch

diff --git a/drivers/net/i40e/i40e_flow.c b/drivers/net/i40e/i40e_flow.c
index 9acaa1875105..c9676caab5dd 100644
--- a/drivers/net/i40e/i40e_flow.c
+++ b/drivers/net/i40e/i40e_flow.c
@@ -3049,6 +3049,9 @@  i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
 
 			for (i = 0; i < raw_spec->length; i++) {
 				j = i + next_dst_off;
+				if (j >= RTE_ETH_FDIR_MAX_FLEXLEN ||
+						j >= I40E_FDIR_MAX_FLEX_LEN)
+					break;
 				filter->input.flow_ext.flexbytes[j] =
 					raw_spec->pattern[i];
 				filter->input.flow_ext.flex_mask[j] =