DPDK patches and discussions
 help / color / mirror / Atom feed
From: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
To: dev@dpdk.org
Cc: rjarry@redhat.com, stable@dpdk.org
Subject: [PATCH 1/2] fib6: fix memory leak on delete operation
Date: Tue, 14 Oct 2025 18:17:54 +0000	[thread overview]
Message-ID: <20251014181755.114300-1-vladimir.medvedkin@intel.com> (raw)

When deleting a prefix, the first attempt to get next prefix cannot
return NULL as we will at a minimum get the prefix we are trying to
delete, whereas we were rather interested in whether there are other
prefixes within the same subtree, not counting the prefix we are
deleting. To address this, we check if we have found the exact prefix we
started with, and perform another search to see if there are more
prefixes to be found.

In addition to that, doing the searches with _COVER rather than _ALL is
incorrect, because if we are doing search with _COVER rather than _ALL, we
do not dive into the tree to find more specific prefixes within the
prefix we are going to delete, and thus will not notice if our subtree
also has more specific prefixes. To fix it, perform first (and
subsequent) searches with _ALL rather than _COVER.

Finally, when we hit the "tmp == NULL" branch (meaning, when we are
deleting the only node that exists in our subtree), we know that the
rib6_lookup will always return us the node that we are trying to delete,
but this is incorrect because further code will consider this to be our
parent node. Address this by doing another search to find the parent of
the current node.

Fixes: c3e12e0f0354 ("fib: add dataplane algorithm for IPv6")
Cc: stable@dpdk.org

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 lib/fib/trie.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/fib/trie.c b/lib/fib/trie.c
index ff4c750952..5a9978b4ca 100644
--- a/lib/fib/trie.c
+++ b/lib/fib/trie.c
@@ -516,7 +516,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip,
 	struct rte_rib6_node *tmp = NULL;
 	struct rte_rib6_node *node;
 	struct rte_rib6_node *parent;
-	struct rte_ipv6_addr ip_masked;
+	struct rte_ipv6_addr ip_masked, tmp_ip;
 	int ret = 0;
 	uint64_t par_nh, node_nh;
 	uint8_t tmp_depth, depth_diff = 0, parent_depth = 24;
@@ -535,9 +535,25 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip,
 	if (depth > 24) {
 		tmp = rte_rib6_get_nxt(rib, &ip_masked,
 			RTE_ALIGN_FLOOR(depth, 8), NULL,
-			RTE_RIB6_GET_NXT_COVER);
+			RTE_RIB6_GET_NXT_ALL);
+		if (tmp && op == RTE_FIB6_DEL) {
+			/* in case of delete operation, skip the prefix we are going to delete */
+			rte_rib6_get_ip(tmp, &tmp_ip);
+			rte_rib6_get_depth(tmp, &tmp_depth);
+			if (rte_ipv6_addr_eq(&ip_masked, &tmp_ip) && depth == tmp_depth)
+				tmp = rte_rib6_get_nxt(rib, &ip_masked,
+					RTE_ALIGN_FLOOR(depth, 8), tmp, RTE_RIB6_GET_NXT_ALL);
+		}
+
 		if (tmp == NULL) {
 			tmp = rte_rib6_lookup(rib, ip);
+			/**
+			 * in case of delete operation, lookup returns the prefix
+			 * we are going to delete. Find the parent.
+			 */
+			if (tmp && op == RTE_FIB6_DEL)
+				tmp = rte_rib6_lookup_parent(tmp);
+
 			if (tmp != NULL) {
 				rte_rib6_get_depth(tmp, &tmp_depth);
 				parent_depth = RTE_MAX(tmp_depth, 24);
-- 
2.43.0


             reply	other threads:[~2025-10-14 18:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 18:17 Vladimir Medvedkin [this message]
2025-10-14 18:17 ` [PATCH 2/2] fib6: fix tbl8 allocation check logic Vladimir Medvedkin
2025-10-15  9:32   ` Robin Jarry
2025-10-15  9:32 ` [PATCH 1/2] fib6: fix memory leak on delete operation Robin Jarry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251014181755.114300-1-vladimir.medvedkin@intel.com \
    --to=vladimir.medvedkin@intel.com \
    --cc=dev@dpdk.org \
    --cc=rjarry@redhat.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).