Skip to contentSkip to conversation

lpm: fix buffer overflow

PATCH Superseded Vladimir Medvedkin 4 participants 6 messages Oct 8, 2021 – Oct 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lpm: fix buffer overflow

This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=819

The rte_lpm6 keeps routing information for control plane purpose inside the rte_hash table which uses rte_jhash() as a hash function. From the rte_jhash() documentation: If input key is not aligned to four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation).
rte_lpm6 uses 17 bytes keys consisting of IPv6 address (16 bytes) + depth (1 byte).

This patch increases the size of the depth field up to uint32_t and sets the alignment to 4 bytes.

Bugzilla ID: 819

Fixes 86b3b21952a8 ("lpm6: store rules in hash table")
---
 lib/lpm/rte_lpm6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/lpm/rte_lpm6.c +2 -2
index 37baabb..d5e0918 100644
@@ -80,8 +80,8 @@ struct rte_lpm6_rule {
 /** Rules tbl entry key. */
 struct rte_lpm6_rule_key {
 	uint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */
-	uint8_t depth; /**< Rule depth. */
-};
+	uint32_t depth; /**< Rule depth. */
+} __rte_aligned(sizeof(uint32_t));
 
 /* Header of tbl8 */
 struct rte_lpm_tbl8_hdr {
Signature · 1 line
2.7.4
#1 lore raw

Hello Vladimir,

Quoted 13 lines · Vladimir Medvedkin

This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=819

The rte_lpm6 keeps routing information for control plane purpose inside the rte_hash table which uses rte_jhash() as a hash function. From the rte_jhash() documentation: If input key is not aligned to four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation).
rte_lpm6 uses 17 bytes keys consisting of IPv6 address (16 bytes) + depth (1 byte).

Quoted 7 lines

This patch increases the size of the depth field up to uint32_t and sets the alignment to 4 bytes.

Bugzilla ID: 819

Fixes 86b3b21952a8 ("lpm6: store rules in hash table")

This change should be internal, and not breaking ABI, but are we sure we want to backport it?

Quoted 11 lines
---
 lib/lpm/rte_lpm6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/lpm/rte_lpm6.c +0 -0
index 37baabb..d5e0918 100644

lib/lpm/rte_lpm6.c struct rte_lpm6_rule { · line 84

Quoted 7 lines
lib/lpm/rte_lpm6.c +2 -2
@@ -80,8 +80,8 @@ struct rte_lpm6_rule {
 /** Rules tbl entry key. */
 struct rte_lpm6_rule_key {
        uint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */
-       uint8_t depth; /**< Rule depth. */
-};
+       uint32_t depth; /**< Rule depth. */
+} __rte_aligned(sizeof(uint32_t));

I would recommend doing the same than for hash tests: keep growing depth to 32bits, but no enforcement of alignment and add build check on structure size being sizeof(uin32_t) aligned.

Quoted 6 lines
lib/lpm/rte_lpm6.c +0 -1
 /* Header of tbl8 */
 struct rte_lpm_tbl8_hdr {
--

2.7.4

Signature · 1 line
David Marchand
#2 lore raw

Hi David,

Quoted 20 lines · David Marchand

Hello Vladimir,

Quoted 16 lines · Vladimir Medvedkin

This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=819

The rte_lpm6 keeps routing information for control plane purpose inside the rte_hash table which uses rte_jhash() as a hash function.
From the rte_jhash() documentation: If input key is not aligned to
four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation).
rte_lpm6 uses 17 bytes keys consisting of IPv6 address (16 bytes) + depth (1 byte).

This patch increases the size of the depth field up to uint32_t and sets the alignment to 4 bytes.

Quoted 8 lines
Quoted 4 lines

Bugzilla ID: 819

Fixes 86b3b21952a8 ("lpm6: store rules in hash table")

This change should be internal, and not breaking ABI, but are we sure we want to backport it?

I think yes, I don't see any reason why we should not backport it. Do you think we should not?

Quoted 7 lines
Quoted 7 lines
---
  lib/lpm/rte_lpm6.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines

lib/lpm/rte_lpm6.c struct rte_lpm6_rule { · line 84

Quoted 12 lines
lib/lpm/rte_lpm6.c +2 -2
index 37baabb..d5e0918 100644
@@ -80,8 +80,8 @@ struct rte_lpm6_rule {
  /** Rules tbl entry key. */
  struct rte_lpm6_rule_key {
         uint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */
-       uint8_t depth; /**< Rule depth. */
-};
+       uint32_t depth; /**< Rule depth. */
+} __rte_aligned(sizeof(uint32_t));

I would recommend doing the same than for hash tests: keep growing depth to 32bits, but no enforcement of alignment and add build check on structure size being sizeof(uin32_t) aligned.

Agree, will send v2

Quoted 9 lines
Quoted 7 lines
lib/lpm/rte_lpm6.c +0 -1
  /* Header of tbl8 */
  struct rte_lpm_tbl8_hdr {
--

2.7.4

Signature · 2 lines
Regards,
Vladimir
#3 lore raw

PATCH v2 1/1 lpm: fix buffer overflow

In reply to Vladimir Medvedkin

This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=819

The rte_lpm6 keeps routing information for control plane purpose inside the rte_hash table which uses rte_jhash() as a hash function. From the rte_jhash() documentation: If input key is not aligned to four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation).
rte_lpm6 uses 17 bytes keys consisting of IPv6 address (16 bytes) + depth (1 byte).

This patch increases the size of the depth field up to uint32_t and sets the alignment to 4 bytes.

Bugzilla ID: 819

Fixes 86b3b21952a8 ("lpm6: store rules in hash table")
---
 lib/lpm/rte_lpm6.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/lpm/rte_lpm6.c +3 -1
index 37baabb..73768fc 100644
@@ -80,7 +80,7 @@ struct rte_lpm6_rule {
 /** Rules tbl entry key. */
 struct rte_lpm6_rule_key {
 	uint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */
-	uint8_t depth; /**< Rule depth. */
+	uint32_t depth; /**< Rule depth. */
 };
 
 /* Header of tbl8 */
@@ -259,6 +259,8 @@ rte_lpm6_create(const char *name, int socket_id,
 	lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list);
 
 	RTE_BUILD_BUG_ON(sizeof(struct rte_lpm6_tbl_entry) != sizeof(uint32_t));
+	RTE_BUILD_BUG_ON(sizeof(struct rte_lpm6_rule_key) %
+		sizeof(uint32_t) != 0);
 
 	/* Check user arguments. */
 	if ((name == NULL) || (socket_id < -1) || (config == NULL) ||
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#4 lore raw
Quoted 15 lines · Vladimir Medvedkin

This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=819

The rte_lpm6 keeps routing information for control plane purpose inside the rte_hash table which uses rte_jhash() as a hash function. From the rte_jhash() documentation: If input key is not aligned to four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation).
rte_lpm6 uses 17 bytes keys consisting of IPv6 address (16 bytes) + depth (1 byte).

This patch increases the size of the depth field up to uint32_t and sets the alignment to 4 bytes.

Quoted 6 lines

Bugzilla ID: 819

Fixes 86b3b21952a8 ("lpm6: store rules in hash table")
#5 lore raw

22/10/2021 11:07, Bruce Richardson:

Quoted 16 lines · Vladimir Medvedkin
Quoted 15 lines

This patch fixes buffer overflow reported by ASAN, please reference https://bugs.dpdk.org/show_bug.cgi?id=819

The rte_lpm6 keeps routing information for control plane purpose inside the rte_hash table which uses rte_jhash() as a hash function. From the rte_jhash() documentation: If input key is not aligned to four byte boundaries or a multiple of four bytes in length, the memory region just after may be read (but not used in the computation).
rte_lpm6 uses 17 bytes keys consisting of IPv6 address (16 bytes) + depth (1 byte).

This patch increases the size of the depth field up to uint32_t and sets the alignment to 4 bytes.

Quoted 8 lines
Quoted 6 lines

Bugzilla ID: 819

Fixes 86b3b21952a8 ("lpm6: store rules in hash table")

Applied, thanks.