i40e: fix the issue reported by klocwork
PATCH 1/1 i40e: fix the issue reported by klocwork
Klocwork reports array 'src_offset' may use index 16.
In function i40e_srcoff_to_flx_pit, index j + 1 can reach I40E_FDIR_MAX_FLEX_LEN. This patch fixes this issue to avoid array bound.
--- lib/librte_pmd_i40e/i40e_fdir.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
lib/librte_pmd_i40e/i40e_fdir.c +17 -18
@@ -402,28 +402,27 @@ i40e_srcoff_to_flx_pit(const uint16_t *src_offset,while (j <I40E_FDIR_MAX_FLEX_LEN ) { size =1 ; -for (; j <I40E_FDIR_MAX_FLEX_LEN ; j++) { +for (; j <I40E_FDIR_MAX_FLEX_LEN -1 ; j++) {if (src_offset[j +1 ] == src_offset[j] +1 ) size++; -else { - src_tmp = src_offset[j] +1 - size; -/* the flex_pit need to be sort by scr_offset */ -for (i =0 ; i < num; i++) { -if (src_tmp < flex_pit[i].src_offset) -break ; - } -/* if insert required, move backward */ -for (k = num; k > i; k--) - flex_pit[k] = flex_pit[k -1 ]; -/* insert */ - flex_pit[i].dst_offset = j +1 - size; - flex_pit[i].src_offset = src_tmp; - flex_pit[i].size = size; - j++; - num++; +else +break ; + } + src_tmp = src_offset[j] +1 - size; +/* the flex_pit need to be sort by src_offset */ +for (i =0 ; i < num; i++) { +if (src_tmp < flex_pit[i].src_offset)break ; - } } +/* if insert required, move backward */ +for (k = num; k > i; k--) + flex_pit[k] = flex_pit[k -1 ]; +/* insert */ + flex_pit[i].dst_offset = j +1 - size; + flex_pit[i].src_offset = src_tmp; + flex_pit[i].size = size; + j++; + num++; }return num; }
Signature · 1 line
1.9.3
A message that is not in the archive (sent off-list or not yet received): 1423740143-29708-1-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Helin, is this patch valid and important?
2015-02-12 19:22, Jingjing Wu:
Quoted 60 lines
Klocwork reports array '
src_offset' may use index 16.
In functioni40e_srcoff_to_flx_pit, index j + 1 can reachI40E_FDIR_MAX_FLEX_LEN. This patch fixes this issue to avoid array bound.Signed-off-by Jingjing Wu <[email protected]>--- lib/librte_pmd_i40e/i40e_fdir.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)lib/librte_pmd_i40e/i40e_fdir.c +17
-18@@ -402,28 +402,27 @@ i40e_srcoff_to_flx_pit(const uint16_t *src_offset,while (j <I40E_FDIR_MAX_FLEX_LEN ) { size =1 ; -for (; j <I40E_FDIR_MAX_FLEX_LEN ; j++) { +for (; j <I40E_FDIR_MAX_FLEX_LEN -1 ; j++) {if (src_offset[j +1 ] == src_offset[j] +1 ) size++; -else { - src_tmp = src_offset[j] +1 - size; -/* the flex_pit need to be sort by scr_offset */ -for (i =0 ; i < num; i++) { -if (src_tmp < flex_pit[i].src_offset) -break ; - } -/* if insert required, move backward */ -for (k = num; k > i; k--) - flex_pit[k] = flex_pit[k -1 ]; -/* insert */ - flex_pit[i].dst_offset = j +1 - size; - flex_pit[i].src_offset = src_tmp; - flex_pit[i].size = size; - j++; - num++; +else +break ; + } + src_tmp = src_offset[j] +1 - size; +/* the flex_pit need to be sort by src_offset */ +for (i =0 ; i < num; i++) { +if (src_tmp < flex_pit[i].src_offset)break ; - } } +/* if insert required, move backward */ +for (k = num; k > i; k--) + flex_pit[k] = flex_pit[k -1 ]; +/* insert */ + flex_pit[i].dst_offset = j +1 - size; + flex_pit[i].src_offset = src_tmp; + flex_pit[i].size = size; + j++; + num++; }return num; }
Zhang, Helin
Acked-byQuoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jingjing Wu
Sent: Thursday, February 12, 2015 7:22 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH] i40e: fix the issue reported by klocwork
Quoted 6 lines
Klocwork reports array '
src_offset' may use index 16. In functioni40e_srcoff_to_flx_pit, index j + 1 can reachI40E_FDIR_MAX_FLEX_LEN.
This patch fixes this issue to avoid array bound.Signed-off-by Jingjing Wu <[email protected]>
Quoted 3 lines
--- lib/librte_pmd_i40e/i40e_fdir.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
A message that is not in the archive (sent off-list or not yet received): F35DEAC7BCE34641BA9FAC6BCA4A12E70A83F55A-0J0gbvR4kTg/[email protected]
Hi Helin,
Quoted 7 lines
Quoted 6 lines
Klocwork reports array '
src_offset' may use index 16. In functioni40e_srcoff_to_flx_pit, index j + 1 can reachI40E_FDIR_MAX_FLEX_LEN.
This patch fixes this issue to avoid array bound.Signed-off-by Jingjing Wu <[email protected]>Acked-by Helin Zhang <[email protected]>
Please confirm it's a real bug which needs to be fixed in 2.0, and/or you are sure this patch won't bring a new problem.
Thanks
Hi Thomas
Actually it is a bug fix. It would be better to be put in R2.0.
It may not crash, as it just possibly read something out of range. I am waiting the test report from our validation team, and then I will merge that. Thanks for your patience!
Regards,
Helin
Quoted 21 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, March 31, 2015 6:28 PM
To: Zhang, Helin
Cc: [email protected]; Wu, Jingjing
Subject: Re: [dpdk-dev] [PATCH] i40e: fix the issue reported by klocworkHi Helin,
Quoted 7 lines
Quoted 6 lines
Klocwork reports array '
src_offset' may use index 16. In functioni40e_srcoff_to_flx_pit, index j + 1 can reachI40E_FDIR_MAX_FLEX_LEN.
This patch fixes this issue to avoid array bound.Signed-off-by Jingjing Wu <[email protected]>Acked-by Helin Zhang <[email protected]>Please confirm it's a real bug which needs to be fixed in 2.0, and/or you are sure this patch won't bring a new problem.
Thanks
Thomas Monjalon
AppliedQuoted 7 lines
Quoted 6 lines
Klocwork reports array '
src_offset' may use index 16. In functioni40e_srcoff_to_flx_pit, index j + 1 can reachI40E_FDIR_MAX_FLEX_LEN.
This patch fixes this issue to avoid array bound.Signed-off-by Jingjing Wu <[email protected]>Acked-by Helin Zhang <[email protected]>
Applied, thanks
Cao, Min
Tested-byPatch name: [dpdk-dev] [PATCH] i40e: fix the issue reported by klocwork
Test Flag: Tested-by
Tester name: [email protected]
Result summary: total 2 cases, 2passed, 0 failed
Test Case 1:
Name: ipv4 fwd
Environment: OS: Fedora20 3.11.10-301.fc20.x86_64
gcc (GCC) 4.8.2 CPU: Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70GHz NIC: Fortville eagle
Test result: PASSED
Detail: ipv4 fwd
Test Case 2:
Name: ipv6 fwd
Environment: OS: Fedora20 3.11.10-301.fc20.x86_64
gcc (GCC) 4.8.2 CPU: Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70GHz NIC: Fortville eagle
Test result: PASSED
Detail: ipv6 fwd
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jingjing Wu
Sent: Thursday, February 12, 2015 7:22 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH] i40e: fix the issue reported by klocwork
Klocwork reports array 'src_offset' may use index 16.
In function i40e_srcoff_to_flx_pit, index j + 1 can reach I40E_FDIR_MAX_FLEX_LEN. This patch fixes this issue to avoid array bound.
--- lib/librte_pmd_i40e/i40e_fdir.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
lib/librte_pmd_i40e/i40e_fdir.c +17 -18
@@ -402,28 +402,27 @@ i40e_srcoff_to_flx_pit(const uint16_t *src_offset,while (j <I40E_FDIR_MAX_FLEX_LEN ) { size =1 ; -for (; j <I40E_FDIR_MAX_FLEX_LEN ; j++) { +for (; j <I40E_FDIR_MAX_FLEX_LEN -1 ; j++) {if (src_offset[j +1 ] == src_offset[j] +1 ) size++; -else { - src_tmp = src_offset[j] +1 - size; -/* the flex_pit need to be sort by scr_offset */ -for (i =0 ; i < num; i++) { -if (src_tmp < flex_pit[i].src_offset) -break ; - } -/* if insert required, move backward */ -for (k = num; k > i; k--) - flex_pit[k] = flex_pit[k -1 ]; -/* insert */ - flex_pit[i].dst_offset = j +1 - size; - flex_pit[i].src_offset = src_tmp; - flex_pit[i].size = size; - j++; - num++; +else +break ; + } + src_tmp = src_offset[j] +1 - size; +/* the flex_pit need to be sort by src_offset */ +for (i =0 ; i < num; i++) { +if (src_tmp < flex_pit[i].src_offset)break ; - } } +/* if insert required, move backward */ +for (k = num; k > i; k--) + flex_pit[k] = flex_pit[k -1 ]; +/* insert */ + flex_pit[i].dst_offset = j +1 - size; + flex_pit[i].src_offset = src_tmp; + flex_pit[i].size = size; + j++; + num++; }return num; }
Signature · 1 line
1.9.3