Skip to contentSkip to conversation

lpm: fix overflow issue

PATCH Applied Igor Ryzhov 3 participants 6 messages Feb 20, 2015 – Feb 24, 2015 3 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lpm: fix overflow issue

LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.

---
 lib/librte_lpm/rte_lpm.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_lpm/rte_lpm.c +3 -0
index 983e04b..cc51210 100644
@@ -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;
Signature · 1 line
1.9.3 (Apple Git-50)
#2 lore raw
In reply to a message not in the archive

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

Quoted 28 lines · Igor Ryzhov

LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.

---
 lib/librte_lpm/rte_lpm.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_lpm/rte_lpm.c +3 -0
index 983e04b..cc51210 100644
@@ -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)

Signature · 2 lines
Regards,
Igor Ryzhov
#4 lore raw
In reply to a message not in the archive

Sorry I missed this Friday. I'll look at it shortly.

On 21 Feb 2015, at 22:56, Igor Ryzhov <[email protected]<mailto:[email protected]>> wrote:

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 <[email protected]<mailto:[email protected]>> wrote:
LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.

---
 lib/librte_lpm/rte_lpm.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_lpm/rte_lpm.c +3 -0
index 983e04b..cc51210 100644
@@ -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)

--
Regards,
Igor Ryzhov

#6 lore raw
In reply to a message not in the archive

Great. The easiest way to reproduce the issue is to fill LPM table with rules using only one depth and try to add another one rule with same depth. Rule will be successfully added and memory will be corrupted.

воскресенье, 22 февраля 2015 г. пользователь Richardson, Bruce написал:

Quoted 53 lines

Sorry I missed this Friday. I'll look at it shortly.

On 21 Feb 2015, at 22:56, Igor Ryzhov <[email protected] <javascript:;> <mailto:[email protected] <javascript:;>>> wrote:

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 <[email protected] <javascript:;><mailto:[email protected] <javascript:;>>> 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 <[email protected] <javascript:;><mailto:

[email protected] <javascript:;>>>

---
 lib/librte_lpm/rte_lpm.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_lpm/rte_lpm.c +3 -0
index 983e04b..cc51210 100644
@@ -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)

--
Regards,
Igor Ryzhov

#7 lore raw
In reply to a message not in the archive
Quoted 3 lines · Igor Ryzhov

LPM table overflow may occur if table is full and added rule has the biggest depth that already have some rules.

Quoted 21 lines
---
 lib/librte_lpm/rte_lpm.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_lpm/rte_lpm.c +3 -0
index 983e04b..cc51210 100644
@@ -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;
Signature · 1 line
1.9.3 (Apple Git-50)