Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH] kernfs: don't take a failed id allocation for a wrap
@ 2026-12-02 19:40 Josef Bacik
  2026-12-03 19:13 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Josef Bacik @ 2026-12-02 19:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Tejun Heo
  Cc: Christian Brauner, driver-core, linux-fsdevel, linux-kernel

After one failed id allocation every new node of that kernfs root gets an
inode number above 32 bits on a 64 bit kernel, and the 32 bit stat() and
getdents() fail on it with EOVERFLOW until the root goes away.

__kernfs_new_node() stores the result of idr_alloc_cyclic() in the u32
last_id_lowbits even when it is an errno. The next id is below that
value, so id_highbits is incremented as if the low bits had wrapped.

Reproduced with failslab on radix_tree_node while making cgroups, the
inode number of the first cgroup made after the ENOMEM:

    before: 0x1000002c0
    after:  0x2c0

Getting the last id once more is a wrap as well, and the stored errno
covered for that after an ENOSPC.

Fix by only recording ids that were allocated, and by counting an id
equal to the last one as a wrap.

Fixes: e23f568aa63f ("kernfs: fix ino wrap-around detection")
Signed-off-by: Josef Bacik <josef@bacik.io>
---
 fs/kernfs/dir.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 800af10d9511e..95563c73aed78 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -671,10 +671,12 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
 	idr_preload(GFP_KERNEL);
 	spin_lock(&root->kernfs_idr_lock);
 	ret = idr_alloc_cyclic(&root->ino_idr, kn, 1, 0, GFP_ATOMIC);
-	if (ret >= 0 && ret < root->last_id_lowbits)
-		root->id_highbits++;
+	if (ret >= 0) {
+		if (ret <= root->last_id_lowbits)
+			root->id_highbits++;
+		root->last_id_lowbits = ret;
+	}
 	id_highbits = root->id_highbits;
-	root->last_id_lowbits = ret;
 	spin_unlock(&root->kernfs_idr_lock);
 	idr_preload_end();
 	if (ret < 0)
---
base-commit: b8e026b973764a52b92c0cdc1d3cf96f2abc1058
change-id: 20261202-b4-kernfs-id-wrap-99d9a77c1300

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 19:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 19:40 [PATCH] kernfs: don't take a failed id allocation for a wrap Josef Bacik
2026-12-03 19:13 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox