[dpdk-dev] lpm: fix overflow issue

Message ID 1424438206-29526-1-git-send-email-iryzhov@nfware.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Igor Ryzhov Feb. 20, 2015, 1:16 p.m. UTC
  LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
 lib/librte_lpm/rte_lpm.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Igor Ryzhov Feb. 21, 2015, 10:56 p.m. UTC | #1
Hello again. Will anybody review this patch?
This is really critical issue, because it can lead to memory corruption and
break any program using LPM.

CCing this to Bruce Richardson, because he is maintainer of LPM.

Regards,
Igor Ryzhov

On Fri, Feb 20, 2015 at 4:16 PM, Igor Ryzhov <iryzhov@nfware.com> wrote:

> LPM table overflow may occur if table is full and added rule has the
> biggest depth that already have some rules.
>
> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
> ---
>  lib/librte_lpm/rte_lpm.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
> index 983e04b..cc51210 100644
> --- a/lib/librte_lpm/rte_lpm.c
> +++ b/lib/librte_lpm/rte_lpm.c
> @@ -298,6 +298,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked,
> uint8_t depth,
>                                 return rule_index;
>                         }
>                 }
> +
> +               if (rule_index == lpm->max_rules)
> +                       return -ENOSPC;
>         } else {
>                 /* Calculate the position in which the rule will be
> stored. */
>                 rule_index = 0;
> --
> 1.9.3 (Apple Git-50)
>
>
  
Bruce Richardson Feb. 22, 2015, 8:29 p.m. UTC | #2
On Fri, Feb 20, 2015 at 04:16:46PM +0300, Igor Ryzhov wrote:
> LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.
> 
> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>

> ---
>  lib/librte_lpm/rte_lpm.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
> index 983e04b..cc51210 100644
> --- a/lib/librte_lpm/rte_lpm.c
> +++ b/lib/librte_lpm/rte_lpm.c
> @@ -298,6 +298,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
>  				return rule_index;
>  			}
>  		}
> +
> +		if (rule_index == lpm->max_rules)
> +			return -ENOSPC;
>  	} else {
>  		/* Calculate the position in which the rule will be stored. */
>  		rule_index = 0;
> -- 
> 1.9.3 (Apple Git-50)
>
  
Thomas Monjalon Feb. 24, 2015, 1:09 a.m. UTC | #3
2015-02-22 20:29, Bruce Richardson:
> On Fri, Feb 20, 2015 at 04:16:46PM +0300, Igor Ryzhov wrote:
> > LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.
> > 
> > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index 983e04b..cc51210 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -298,6 +298,9 @@  rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 				return rule_index;
 			}
 		}
+
+		if (rule_index == lpm->max_rules)
+			return -ENOSPC;
 	} else {
 		/* Calculate the position in which the rule will be stored. */
 		rule_index = 0;