net/igc: fix memory illegal accesses
PATCH 1/1 net/igc: fix memory illegal accesses
From: Alvin Zhang <[email protected]>
Add memory access out-of-bounds check.
--- drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/igc/igc_ethdev.c +10 -2
@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;
@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */
@@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =
@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;
@@ -2330,12 +2336,14 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE )); +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta_conf[idx].reta[shift + j] = reta.bytes[j];
Signature · 1 line
1.8.3.1
hi, alvin
Quoted 3 lines · On 5/7/2020 10:01 AM, [email protected] wrote:
From: Alvin Zhang <[email protected]>
Add memory access out-of-bounds check.
Could you explain why add ...? If not add, what issue?
Quoted 23 lines
Fixes bd3fcf0d0fa1 (net/igc: support RSS)Signed-off-by Alvin Zhang <[email protected]>--- drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/igc/igc_ethdev.c +2
-0@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, · line 2284
Quoted 6 lines
drivers/net/igc/igc_ethdev.c +2
-1@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))
alignment should be match above parentheses.
Quoted 21 lines
drivers/net/igc/igc_ethdev.c +3
-0continue ;/* check mask whether need to read the register value first */ @@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, · line 2340
Quoted 6 lines
drivers/net/igc/igc_ethdev.c +2
-1@@ -2330,12 +2336,14 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))
the same as above.
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, · line 2346
Quoted 6 lines
drivers/net/igc/igc_ethdev.c +1
-0continue ;/* read register and get the queue index */ reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE )); +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );
need null line or no need, please check it at the place and before.
Quoted 3 lines
drivers/net/igc/igc_ethdev.c +0
-0for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta_conf[idx].reta[shift + j] = reta.bytes[j];
Hi Jia,
First of all, this is a coverity issue, and it's really a false positives. But do some macro checking will improve code robustness.
Thanks,
Alvin
Quoted 115 lines
-----Original Message-----
From: Guo, Jia
Sent: Thursday, May 7, 2020 2:30 PM
To: Zhang, AlvinX <[email protected]>; [email protected]
Cc: Zhao1, Wei <[email protected]>; Ye, Xiaolong <[email protected]>
Subject: Re: [PATCH] net/igc: fix memory illegal accesseshi, alvin
Quoted 3 lines · On 5/7/2020 10:01 AM, [email protected] wrote:
From: Alvin Zhang <[email protected]>
Add memory access out-of-bounds check.
Could you explain why add ...? If not add, what issue?
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct
Quoted 14 lines
Fixes bd3fcf0d0fa1 (net/igc: support RSS)Signed-off-by Alvin Zhang <[email protected]>--- drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/net/igc/igc_ethdev.cindex 16d98c6..ced8ffd 100644drivers/net/igc/igc_ethdev.c +0
-0@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct
rte_eth_dev*dev,drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 4 lines
drivers/net/igc/igc_ethdev.c +1
-0return -EINVAL ; } + RTE_BUILD_BUG_ON(ETH_RSS_RETA_SIZE_128 %
IGC_RSS_RDT_REG_SIZE);drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 3 lines
drivers/net/igc/igc_ethdev.c +1
-0+/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ){
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct
Quoted 2 lines
drivers/net/igc/igc_ethdev.c +0
-0union igc_rss_reta_reg reta, reg;@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct
rte_eth_dev*dev,drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 6 lines
drivers/net/igc/igc_ethdev.c +2
-1IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -
IGC_RSS_RDT_REG_SIZE))alignment should be match above parentheses.
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 3 lines
drivers/net/igc/igc_ethdev.c +0
-0continue ;/* check mask whether need to read the register value first */ @@
Quoted 1 line
-2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct
rte_eth_dev*dev,
Quoted 1 line
IGC_RETA(i /
IGC_RSS_RDT_REG_SIZE));drivers/net/igc/igc_ethdev.c
Quoted 3 lines
/* update the register */
drivers/net/igc/igc_ethdev.c +1
-0+ RTE_BUILD_BUG_ON(sizeof(reta.bytes) !=
IGC_RSS_RDT_REG_SIZE);drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct
Quoted 4 lines
for (j = 0; j < IGC_RSS_RDT_REG_SIZE; j++) { if (mask & (1u << j)) reta.bytes[j] =drivers/net/igc/igc_ethdev.c +0
-0@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct
rte_eth_dev*dev,drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 4 lines
drivers/net/igc/igc_ethdev.c +1
-0return -EINVAL ; } + RTE_BUILD_BUG_ON(ETH_RSS_RETA_SIZE_128 %
IGC_RSS_RDT_REG_SIZE);drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 3 lines
drivers/net/igc/igc_ethdev.c +1
-0+/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ){
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct
Quoted 2 lines
drivers/net/igc/igc_ethdev.c +0
-0union igc_rss_reta_reg reta;@@ -2330,12 +2336,14 @@ static int eth_igc_vlan_tpid_set(struct
rte_eth_dev*dev,drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 6 lines
drivers/net/igc/igc_ethdev.c +2
-1IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -
IGC_RSS_RDT_REG_SIZE))the same as above.
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
Quoted 6 lines
drivers/net/igc/igc_ethdev.c +1
-0continue ;/* read register and get the queue index */ reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE )); + RTE_BUILD_BUG_ON(sizeof(reta.bytes) !=
IGC_RSS_RDT_REG_SIZE);need null line or no need, please check it at the place and before.
Quoted 3 lines
drivers/net/igc/igc_ethdev.c +0
-0for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta_conf[idx].reta[shift + j] = reta.bytes[j];
PATCH v2 1/1 net/igc: fix memory illegal accesses
In reply to [email protected]From: Alvin Zhang <[email protected]>
Fix some out-of-bounds memory issues, they may lead to wrong results or affect application stability.
V2: update git log
--- drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/igc/igc_ethdev.c +10 -2
@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;
@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */
@@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =
@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;
@@ -2330,10 +2336,12 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE ); reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE ));for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {
Signature · 1 line
1.8.3.1
PATCH v2 1/1 net/igc: fix memory illegal accesses
From: Alvin Zhang <[email protected]>
Fix some out-of-bounds memory issues, they may lead to wrong results or affect application stability.
---
V2: update git log
drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/igc/igc_ethdev.c +10 -2
@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;
@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */
@@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =
@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;
@@ -2330,10 +2336,12 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE ); reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE ));for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {
Signature · 1 line
1.8.3.1
Quoted 60 lines · On 5/7/2020 5:31 PM, [email protected] wrote:
From: Alvin Zhang <[email protected]>
Fix some out-of-bounds memory issues, they may lead to wrong results or affect application stability.
Fixes bd3fcf0d0fa1 (net/igc: support RSS)Signed-off-by Alvin Zhang <[email protected]>---
V2: update git log
drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/igc/igc_ethdev.c +7
-1@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */ @@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;@@ -2330,10 +2336,12 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */
drivers/net/igc/igc_ethdev.c static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, · line 2347
Quoted 10 lines
drivers/net/igc/igc_ethdev.c +3
-1-if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE ); reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE ));for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {
Quoted 7 lines · On 05/07, [email protected] wrote:
From: Alvin Zhang <[email protected]>
Fix some out-of-bounds memory issues, they may lead to wrong results or affect application stability.
Fixes bd3fcf0d0fa1 (net/igc: support RSS)
Please append the coverity number, you can refer to other fixes in the commit history.
Thanks,
Xiaolong
Quoted 66 lines
Signed-off-by Alvin Zhang <[email protected]>---
V2: update git log
drivers/net/igc/igc_ethdev.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/igc/igc_ethdev.c +10
-2@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */ @@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;@@ -2330,10 +2336,12 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE ); reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE ));for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {Signature · 1 line
1.8.3.1
PATCH v3 1/1 net/igc: fix memory illegal accesses
In reply to [email protected]From: Alvin Zhang <[email protected]>
Fix some out-of-bounds memory issues, they may lead to wrong results or affect application stability.
Coverity issue: 357759, 357713
---
V2: update git log
V3: update git log
drivers/net/igc/igc_ethdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/igc/igc_ethdev.c +10 -2
@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;
@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */
@@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =
@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;
@@ -2330,10 +2336,12 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE ); reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE ));for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {
Signature · 1 line
1.8.3.1
Ye Xiaolong
AppliedQuoted 75 lines · On 05/08, [email protected] wrote:
From: Alvin Zhang <[email protected]>
Fix some out-of-bounds memory issues, they may lead to wrong results or affect application stability.
Coverity issue: 357759, 357713
Fixes bd3fcf0d0fa1 (net/igc: support RSS)Signed-off-by Alvin Zhang <[email protected]>---
V2: update git log
V3: update git log
drivers/net/igc/igc_ethdev.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)drivers/net/igc/igc_ethdev.c +10
-2@@ -2266,6 +2266,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* set redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta, reg;@@ -2278,7 +2280,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to update the register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* check mask whether need to read the register value first */ @@ -2289,6 +2292,7 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));/* update the register */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE );for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {if (mask & (1u << j)) reta.bytes[j] =@@ -2318,6 +2322,8 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,return -EINVAL ; } +RTE_BUILD_BUG_ON (ETH_RSS_RETA_SIZE_128 %IGC_RSS_RDT_REG_SIZE ); +/* read redirection table */ for (i =0 ; i <ETH_RSS_RETA_SIZE_128 ; i +=IGC_RSS_RDT_REG_SIZE ) {union igc_rss_reta_reg reta;@@ -2330,10 +2336,12 @@ static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev, IGC_RSS_RDT_REG_SIZE_MASK);/* if no need to read register */ -if (!mask) +if (!mask || + shift > (RTE_RETA_GROUP_SIZE -IGC_RSS_RDT_REG_SIZE ))continue ;/* read register and get the queue index */ +RTE_BUILD_BUG_ON (sizeof (reta.bytes) !=IGC_RSS_RDT_REG_SIZE ); reta.dword =IGC_READ_REG_LE_VALUE (hw,IGC_RETA (i /IGC_RSS_RDT_REG_SIZE ));for (j =0 ; j <IGC_RSS_RDT_REG_SIZE ; j++) {Signature · 1 line
1.8.3.1
Applied to dpdk-next-net-intel, Thanks.