[PATCH 0/2] kernfs: fix two races in __kernfs_new_node()

From: Josef Bacik

Date: Wed Dec 02 2026 - 11:49:50 EST


Hello,

kernfs_find_and_get_node_by_id() can find a node in the idr while
__kernfs_new_node() is still setting it up, and after its error path has
freed it. Patch 1 sets the deactivated bias before the node goes into
the idr, and patch 2 frees the node with kernfs_free_rcu() on that error
path.

Each bug reproduced in QEMU with KASAN, lockdep and kmemleak only with
added delays, plus a forced failure for patch 2, and the same runs are
clean with both patches. kernfs_test and the cgroup test_core,
test_kill, test_pids and test_freezer selftests pass.

This is against vfs.fixes, since the recent kernfs fixes went through
Christian's tree, and it applies to mainline as well. Thanks,

Josef

---
Josef Bacik (2):
kernfs: deactivate a new node before publishing its id
kernfs: RCU free a new node that was already in the idr

fs/kernfs/dir.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
---
base-commit: b8e026b973764a52b92c0cdc1d3cf96f2abc1058
change-id: 20261202-b4-kernfs-new-node-cfcf607114b4