Thread (7 messages) 7 messages, 2 authors, 21d ago

Re: [PATCH net] tipc: fix UAF in cleanup_bearer() due to premature dst_cache_destroy()

From: Eric Dumazet <edumazet@google.com>
Date: 2026-06-23 13:58:25
Subsystem: networking [general], the rest, tipc network layer · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds, Jon Maloy

On Tue, Jun 23, 2026 at 6:56 AM Xin Long [off-list ref] wrote:
On Tue, Jun 23, 2026 at 2:35 AM Eric Dumazet [off-list ref] wrote:
quoted
On Mon, Jun 22, 2026 at 10:37 PM Eric Dumazet [off-list ref] wrote:
quoted
On Mon, Jun 22, 2026 at 6:48 PM Xin Long [off-list ref] wrote:
quoted
quoted
Could this corrupt the list for concurrent RCU readers?
When list_del_rcu() is called, it intentionally leaves the next pointer
intact so concurrent readers can continue their traversal. However, the
immediate call to list_add() overwrites both the next and prev pointers
to link the entry into private_list.
If a concurrent reader is currently positioned at rcast, won't it follow
the newly clobbered next pointer and jump from the original RCU list
directly into private_list?
Because private_list is allocated on the local stack, the reader might
interpret stack memory as a struct udp_replicast. Furthermore, the reader
would miss its loop termination condition because it expects to reach the
original list head, potentially resulting in an infinite loop or a crash.
[ ... ]
I think you are right.

Considering there is already one rcu_head in udp_replicast I will use it in V2.
While looking at many syzbot reports with RTNL pressure. I found this
gem in  tipc_exit_net()

while (atomic_read(&tn->wq_count))
      cond_resched();

On some kernel builds cond_resched() can be a NOP, so we might loop
here for a while :/
True, thanks for the report,

I think a cleanup_wq should be added for 'ub->work' instead of using system_wq,
and then do flush_workqueue(cleanup_wq) in tipc_init_net().
 I will send a series of 2 patches.

Second one looks like:

More complex stuff can be added later in net-next.

commit 2f6b56e70f7048a9a2577715b8cfdb0ec94c2469
Author: Eric Dumazet [off-list ref]
Date:   Tue Jun 23 06:48:33 2026 +0000

    tipc: avoid busy looping in tipc_exit_net()

    Blamed commit introduced a busy-wait loop in tipc_exit_net()
    to wait for pending UDP bearer cleanup works to complete:

           while (atomic_read(&tn->wq_count))
                   cond_resched();

    This loop can busy-wait for a long time if cond_resched() is a NOP. This
    typically happens if the netns exit is executed by a high priority task,
    or under kernels configured without preemption (CONFIG_PREEMPT_NONE). In
    such cases, it wastes CPU cycles and can lead to soft lockups.

    Fix this by replacing the busy loop with wait_var_event(), allowing the
    thread to sleep properly until the work queue count reaches zero.

    Accordingly, update cleanup_bearer() to use atomic_dec_and_test() and
    wake_up_var() to wake up the waiter when the count drops to zero.

    This uses the global wait queue hash table, avoiding the need to bloat
    struct tipc_net with a wait_queue_head_t. The atomic_dec_and_test()
    provides the necessary memory barrier to ensure the wakeup is not missed.

    Fixes: 04c26faa51d1 ("tipc: wait and exit until all work queues are done")
    Signed-off-by: Eric Dumazet [off-list ref]
    Cc: Xin Long [off-list ref]
    Cc: Jon Maloy [off-list ref]
    Cc: tipc-discussion@lists.sourceforge.net
diff --git a/net/tipc/core.c b/net/tipc/core.c
index 1ddecea1df6e9100334c47a28ff6c065292fb9ad..315975c3be8186784e9c44c9ff69d62c17ffd4b9
100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -45,6 +45,7 @@
 #include "crypto.h"

 #include <linux/module.h>
+#include <linux/wait_bit.h>

 /* configurable TIPC parameters */
 unsigned int tipc_net_id __read_mostly;
@@ -118,8 +119,7 @@ static void __net_exit tipc_exit_net(struct net *net)
 #ifdef CONFIG_TIPC_CRYPTO
        tipc_crypto_stop(&tipc_net(net)->crypto_tx);
 #endif
-       while (atomic_read(&tn->wq_count))
-               cond_resched();
+       wait_var_event(&tn->wq_count, atomic_read(&tn->wq_count) == 0);
 }

 static void __net_exit tipc_pernet_pre_exit(struct net *net)
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
index 66f3cb87a0aaaac8f40e8f237ab9a44d539b1cd8..62ae7f5b58409c89798c915dee752ac42487581f
100644
--- a/net/tipc/udp_media.c
+++ b/net/tipc/udp_media.c
@@ -40,6 +40,7 @@
 #include <linux/igmp.h>
 #include <linux/kernel.h>
 #include <linux/workqueue.h>
+#include <linux/wait_bit.h>
 #include <linux/list.h>
 #include <net/sock.h>
 #include <net/ip.h>
@@ -830,7 +831,8 @@ static void cleanup_bearer(struct work_struct *work)
        synchronize_net();

        dst_cache_destroy(&ub->rcast.dst_cache);
-       atomic_dec(&tn->wq_count);
+       if (atomic_dec_and_test(&tn->wq_count))
+               wake_up_var(&tn->wq_count);
        kfree(ub);
 }
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help