Re: [PATCH] kernfs: don't take a failed id allocation for a wrap
From: Tejun Heo
Date: Thu Dec 03 2026 - 14:13:57 EST
On Wed, Dec 02, 2026 at 02:40:46PM -0500, Josef Bacik wrote:
> 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@xxxxxxxx>
Acked-by: Tejun Heo <tj@xxxxxxxxxx>
Thanks.
--
tejun