All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Mikhalitsyn <alex@amutable.com>
To: Josef Bacik <josef@bacik.io>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tejun Heo <tj@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
	driver-core@lists.linux.dev,  linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernfs: don't take a failed id allocation for a wrap
Date: Fri, 04 Dec 2026 10:42:38 +0100	[thread overview]
Message-ID: <af5baefa121be4291ed1ae39f3d10118da7fab70.camel@amutable.com> (raw)
In-Reply-To: <20261202-b4-kernfs-id-wrap-v1-1-99d9a77c1300@bacik.io>

On Wed, 2026-12-02 at 14:40 -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@bacik.io>

LGTM

Please, feel free to add:

Reviewed-by: Alexander Mikhalitsyn <alex@amutable.com>

> ---
>  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

      parent reply	other threads:[~2026-12-04  9:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-12-04  9:42 ` Alexander Mikhalitsyn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af5baefa121be4291ed1ae39f3d10118da7fab70.camel@amutable.com \
    --to=alex@amutable.com \
    --cc=brauner@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=josef@bacik.io \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.