net/softnic: fix out of bound access
PATCH 1/1 net/softnic: fix out of bound access
This patch fixes out of bound access of an array.
Coverity issue: 363466, 363459
--- drivers/net/softnic/rte_eth_softnic_tm.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/softnic/rte_eth_softnic_tm.c +13 -2
@@ -1147,10 +1147,15 @@ update_subport_tc_rate(struct rte_eth_dev *dev,struct tm_node *ns = np->parent_node;uint32_t subport_id =tm_node_subport_id (dev, ns);struct tm_params *t = &p->soft.tm.params; -uint32_t subport_profile_id = t->subport_to_profile[subport_id]; +uint32_t subport_profile_id;struct tm_shaper_profile *sp_old =tm_shaper_profile_search (dev, ss->shaper_profile_id); +if (subport_id <TM_MAX_SUBPORT_PROFILE ) + subport_profile_id = t->subport_to_profile[subport_id]; +else +return -1 ; +/* Derive new subport configuration. */ memcpy(&subport_profile, &p->soft.tm.params.subport_profile[subport_profile_id],
@@ -2370,7 +2375,10 @@ subport_profile_get(struct rte_eth_dev *dev, struct tm_node *np)struct tm_params *t = &p->soft.tm.params;uint32_t subport_id =tm_node_subport_id (dev, np->parent_node); -return &t->subport_profile[subport_id]; +if (subport_id <TM_MAX_SUBPORT_PROFILE ) +return &t->subport_profile[subport_id]; +else +return NULL ; } static void
@@ -3024,6 +3032,9 @@ update_subport_rate(struct rte_eth_dev *dev,struct rte_sched_subport_profile_params profile1;uint32_t subport_profile_id; +if (profile0 ==NULL ) +return -1 ; +/* Derive new pipe profile. */ memcpy (&profile1, profile0,sizeof (profile1)); profile1.tb_rate = sp->params.peak.rate;
Signature · 1 line
2.17.1
Quoted 30 lines
-----Original Message-----
From: Dharmappa, Savinay <[email protected]>
Sent: Monday, October 19, 2020 11:50 AM
To: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>; [email protected]
Cc: Dharmappa, Savinay <[email protected]>
Subject: [PATCH v1] net/softnic: fix out of bound accessThis patch fixes out of bound access of an array.
Coverity issue: 363466, 363459
Fixes b5dfa6703d49 ("net/softnic: update subport rate dynamically")Signed-off-by Savinay Dharmappa <[email protected]>--- drivers/net/softnic/rte_eth_softnic_tm.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/net/softnic/rte_eth_softnic_tm.c +0
-0@@ -1147,10 +1147,15 @@ update_subport_tc_rate(struct rte_eth_dev *dev, struct tm_node *ns = np->parent_node;uint32_t subport_id =tm_node_subport_id (dev, ns);struct tm_params *t = &p->soft.tm.params;
drivers/net/softnic/rte_eth_softnic_tm.c update_subport_tc_rate(struct rte_eth_dev · line 1159
Quoted 10 lines
drivers/net/softnic/rte_eth_softnic_tm.c +6
-1-uint32_t subport_profile_id = t->subport_to_profile[subport_id]; +uint32_t subport_profile_id;struct tm_shaper_profile *sp_old =tm_shaper_profile_search (dev, ss->shaper_profile_id); +if (subport_id <TM_MAX_SUBPORT_PROFILE ) + subport_profile_id = t->subport_to_profile[subport_id]; +else +return -1 ; +
For readability purpose, please use our typical way to handle checks, which is:
if (subport_id >= TM_MAX_SUBPORT_PROFILE) return -1; subport_profile_id = t->subport_to_profile[subport_id];
Quoted 4 lines
drivers/net/softnic/rte_eth_softnic_tm.c +0
-0/* Derive new subport configuration. */ memcpy(&subport_profile,drivers/net/softnic/rte_eth_softnic_tm.c +0
-0&p->soft.tm.params.subport_profile[subport_profile_id],
drivers/net/softnic/rte_eth_softnic_tm.c subport_profile_get(struct rte_eth_dev *dev, · line 2383
Quoted 10 lines
drivers/net/softnic/rte_eth_softnic_tm.c +4
-1@@ -2370,7 +2375,10 @@ subport_profile_get(struct rte_eth_dev *dev, struct tm_node *np)struct tm_params *t = &p->soft.tm.params;uint32_t subport_id =tm_node_subport_id (dev, np->parent_node); -return &t->subport_profile[subport_id]; +if (subport_id <TM_MAX_SUBPORT_PROFILE ) +return &t->subport_profile[subport_id]; +else +return NULL ; }
Same comment here.
Quoted 14 lines
drivers/net/softnic/rte_eth_softnic_tm.c +3
-1static void@@ -3024,6 +3032,9 @@ update_subport_rate(struct rte_eth_dev *dev,struct rte_sched_subport_profile_params profile1;uint32_t subport_profile_id; +if (profile0 ==NULL ) +return -1 ; +/* Derive new pipe profile. */ memcpy (&profile1, profile0,sizeof (profile1)); profile1.tb_rate = sp->params.peak.rate; --2.17.1
PATCH v2 1/1 net/softnic: fix out of bound access
In reply to Savinay DharmappaThis patch fixes out of bound access of an array.
Coverity issue: 363466, 363459
---
v2: addressed review comments of v1
--- drivers/net/softnic/rte_eth_softnic_tm.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/softnic/rte_eth_softnic_tm.c +12 -1
@@ -1147,10 +1147,15 @@ update_subport_tc_rate(struct rte_eth_dev *dev,struct tm_node *ns = np->parent_node;uint32_t subport_id =tm_node_subport_id (dev, ns);struct tm_params *t = &p->soft.tm.params; -uint32_t subport_profile_id = t->subport_to_profile[subport_id]; +uint32_t subport_profile_id;struct tm_shaper_profile *sp_old =tm_shaper_profile_search (dev, ss->shaper_profile_id); +if (subport_id >=TM_MAX_SUBPORT_PROFILE ) +return -1 ; + + subport_profile_id = t->subport_to_profile[subport_id]; +/* Derive new subport configuration. */ memcpy(&subport_profile, &p->soft.tm.params.subport_profile[subport_profile_id],
@@ -2370,6 +2375,9 @@ subport_profile_get(struct rte_eth_dev *dev, struct tm_node *np)struct tm_params *t = &p->soft.tm.params;uint32_t subport_id =tm_node_subport_id (dev, np->parent_node); +if (subport_id >=TM_MAX_SUBPORT_PROFILE ) +return NULL ; +return &t->subport_profile[subport_id]; }
@@ -3024,6 +3032,9 @@ update_subport_rate(struct rte_eth_dev *dev,struct rte_sched_subport_profile_params profile1;uint32_t subport_profile_id; +if (profile0 ==NULL ) +return -1 ; +/* Derive new pipe profile. */ memcpy (&profile1, profile0,sizeof (profile1)); profile1.tb_rate = sp->params.peak.rate;
Signature · 1 line
2.17.1
Quoted 67 lines
-----Original Message-----
From: Dharmappa, Savinay <[email protected]>
Sent: Monday, October 19, 2020 12:52 PM
To: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>; [email protected]
Cc: Dharmappa, Savinay <[email protected]>
Subject: [PATCH v2] net/softnic: fix out of bound accessThis patch fixes out of bound access of an array.
Coverity issue: 363466, 363459
Fixes b5dfa6703d49 ("net/softnic: update subport rate dynamically")Signed-off-by Savinay Dharmappa <[email protected]>---
v2: addressed review comments of v1--- drivers/net/softnic/rte_eth_softnic_tm.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/net/softnic/rte_eth_softnic_tm.c +6
-1@@ -1147,10 +1147,15 @@ update_subport_tc_rate(struct rte_eth_dev *dev, struct tm_node *ns = np->parent_node;uint32_t subport_id =tm_node_subport_id (dev, ns);struct tm_params *t = &p->soft.tm.params; -uint32_t subport_profile_id = t->subport_to_profile[subport_id]; +uint32_t subport_profile_id;struct tm_shaper_profile *sp_old =tm_shaper_profile_search (dev, ss->shaper_profile_id); +if (subport_id >=TM_MAX_SUBPORT_PROFILE ) +return -1 ; + + subport_profile_id = t->subport_to_profile[subport_id]; +/* Derive new subport configuration. */ memcpy(&subport_profile,drivers/net/softnic/rte_eth_softnic_tm.c +6
-1&p->soft.tm.params.subport_profile[subport_profile_id],@@ -2370,6 +2375,9 @@ subport_profile_get(struct rte_eth_dev *dev, struct tm_node *np)struct tm_params *t = &p->soft.tm.params;uint32_t subport_id =tm_node_subport_id (dev, np->parent_node); +if (subport_id >=TM_MAX_SUBPORT_PROFILE ) +return NULL ; +return &t->subport_profile[subport_id]; }@@ -3024,6 +3032,9 @@ update_subport_rate(struct rte_eth_dev *dev,struct rte_sched_subport_profile_params profile1;uint32_t subport_profile_id; +if (profile0 ==NULL ) +return -1 ; +/* Derive new pipe profile. */ memcpy (&profile1, profile0,sizeof (profile1)); profile1.tb_rate = sp->params.peak.rate; --
Quoted 1 line
2.17.1
Ferruh Yigit
AppliedQuoted 10 lines · Cristian
Quoted 10 lines
-----Original Message-----
From: Dharmappa, Savinay <[email protected]>
Sent: Monday, October 19, 2020 12:52 PM
To: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>; [email protected]
Cc: Dharmappa, Savinay <[email protected]>
Subject: [PATCH v2] net/softnic: fix out of bound access
Quoted 8 lines
Quoted 6 lines
This patch fixes out of bound access of an array.
Coverity issue: 363466, 363459
Fixes b5dfa6703d49 ("net/softnic: update subport rate dynamically")Signed-off-by Savinay Dharmappa <[email protected]> >
Applied to dpdk-next-net/main, thanks.