[PATCH net v2 2/6] tipc: fix dangling link in cluster_scope list in tipc_service_delete()

From
Tung Nguyen <tung.quang.nguyen@est.tech>
Date
2026-11-02 03:43:05
Reply to
Tung Nguyen, 2026-11-02
The TIPC name table uses the cluster_scope list to store the
following publications:

- User publications with cluster scope from the local node:

  __tipc_bind()
   tipc_sk_publish()
    tipc_nametbl_publish()
     tipc_named_publish()
      list_add_tail(&p->binding_node, &nt->cluster_scope)
    list_add(&p->binding_sock, &tsk->publications)

- Protocol publications of type TIPC_NODE_STATE (0) with cluster
  scope from the local node:

  tipc_net_finalize()
   tipc_nametbl_publish()
    tipc_named_publish()
     list_add_tail(&p->binding_node, &nt->cluster_scope)

When a network namespace is destroyed:

- User publications with cluster scope from the local node are removed
  through the following call path:

  tipc_release()
    tipc_sk_withdraw()
     list_for_each_entry_safe(p, safe, &tsk->publications, binding_sock)
      tipc_nametbl_withdraw()
       tipc_named_withdraw()
        list_del(&p->binding_node)

- However, code inspection revealed that tipc_service_delete() does not
  remove self-node TIPC_NODE_STATE publication from the cluster_scope list,
  leaving dangling list entries:

   tipc_service_delete()
    list_for_each_entry_safe()
     tipc_service_remove_publ()
      kfree_rcu(p, rcu);

Fix this by calling list_del() before freeing TIPC_NODE_STATE
publications in tipc_service_delete().

Fixes: 1bb8dce57f4d ("tipc: fix memory leak during module removal")
Signed-off-by: Tung Nguyen <tung.quang.nguyen@est.tech>
---
 net/tipc/name_table.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 6fda36ab1766..73b032ba2f8d 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -934,6 +934,7 @@ int tipc_nametbl_init(struct net *net)
  */
 static void tipc_service_delete(struct net *net, struct tipc_service *sc)
 {
+	struct tipc_net *tn = tipc_net(net);
 	struct service_range *sr, *tmpr;
 	struct publication *p, *tmp;
 
@@ -941,6 +942,13 @@ static void tipc_service_delete(struct net *net, struct tipc_service *sc)
 	rbtree_postorder_for_each_entry_safe(sr, tmpr, &sc->ranges, tree_node) {
 		list_for_each_entry_safe(p, tmp, &sr->all_publ, all_publ) {
 			tipc_service_remove_publ(sr, &p->sk, p->key);
+			if (p->sr.type == TIPC_NODE_STATE &&
+			    p->sr.lower == tn->node_addr &&
+			    p->sr.upper == tn->node_addr &&
+			    p->key == tn->node_addr &&
+			    p->sk.ref == 0 && p->sk.node == tn->node_addr)
+				list_del(&p->binding_node);
+
 			kfree_rcu(p, rcu);
 		}
 		rb_erase_augmented(&sr->tree_node, &sc->ranges, &sr_callbacks);
-- 
2.53.0
Thread (8 messages) 8 messages, 2 authors, last reply 16d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help