]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
eventpoll: defer struct eventpoll free to RCU grace period
authorNicholas Carlini <nicholas@carlini.com>
Tue, 31 Mar 2026 13:25:32 +0000 (15:25 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 2 Apr 2026 19:45:02 +0000 (21:45 +0200)
In certain situations, ep_free() in eventpoll.c will kfree the epi->ep
eventpoll struct while it still being used by another concurrent thread.
Defer the kfree() to an RCU callback to prevent UAF.

Fixes: f2e467a48287 ("eventpoll: Fix semi-unbounded recursion")
Signed-off-by: Nicholas Carlini <nicholas@carlini.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/eventpoll.c

index 5714e900567c499739bb205f43bb6bf73f7ebe54..4b43bf41296d4b27320b896129f1cc947a7eb677 100644 (file)
@@ -226,6 +226,9 @@ struct eventpoll {
         */
        refcount_t refcount;
 
+       /* used to defer freeing past ep_get_upwards_depth_proc() RCU walk */
+       struct rcu_head rcu;
+
 #ifdef CONFIG_NET_RX_BUSY_POLL
        /* used to track busy poll napi_id */
        unsigned int napi_id;
@@ -819,7 +822,8 @@ static void ep_free(struct eventpoll *ep)
        mutex_destroy(&ep->mtx);
        free_uid(ep->user);
        wakeup_source_unregister(ep->ws);
-       kfree(ep);
+       /* ep_get_upwards_depth_proc() may still hold epi->ep under RCU */
+       kfree_rcu(ep, rcu);
 }
 
 /*