All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: linux-unionfs@vger.kernel.org, miklos@szeredi.hu, amir73il@gmail.com
Cc: cui.tao@linux.dev, andrealmeid@igalia.com,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tao Cui <cuitao@kylinos.cn>,
	stable@vger.kernel.org
Subject: Re: [PATCH] ovl: clean up dir on casefold mismatch
Date: Mon, 7 Sep 2026 13:37:55 +0800	[thread overview]
Message-ID: <73236c69-bd81-45e1-8195-59775a34475a@linux.dev> (raw)
In-Reply-To: <20260907045517.1347518-1-cui.tao@linux.dev>



在 2026/9/7 12:55, Tao Cui 写道:
> From: Tao Cui <cuitao@kylinos.cn>
> 
> In ovl_create_real(), the S_IFDIR case checks after a successful
> ovl_do_mkdir() that the new directory inherited the expected casefold
> flag.  On mismatch, err is set to -EINVAL but the directory that was
> just created in the workdir or in the upper layer is left behind.
> 
> The mismatch is reachable: ofs->casefold is fixed at mount time, but
> the casefold flag of the index dir can diverge.  With index=on, a
> pre-existing "index" directory with +F is accepted at mount, and every
> temp mkdir for an index entry inside it fails the check and leaks one
> directory.  Measured on an ext4 casefold upper: 100 directory renames
> left 100 "#nnnn" entries in the index dir, one per failed mkdir,
> growing without bound.
> 
> Clean up the created directory with ovl_cleanup_locked() before
> returning the error.  All callers of ovl_create_real() arrive with the
> parent inode locked (via start_creating()), so the locked variant must
> be used; ovl_cleanup() would deadlock on inode_lock().
> 
> Fixes: dfc7da402ccc9 ("ovl: Check for casefold consistency when creating new dentries")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
> ---
>  fs/overlayfs/dir.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
> index 7beb0af26498..4e451bbd8f97 100644
> --- a/fs/overlayfs/dir.c
> +++ b/fs/overlayfs/dir.c
> @@ -188,6 +188,7 @@ struct dentry *ovl_create_real(struct ovl_fs *ofs, struct dentry *parent,
>  			if (!err && ofs->casefold != ovl_dentry_casefolded(newdentry)) {
>  				pr_warn_ratelimited("wrong inherited casefold (%pd2)\n",
>  						    newdentry);
> +				ovl_cleanup_locked(ofs, dir, newdentry);
>  				err = -EINVAL;
>  			}
>  			break;

Sashiko pointed out that the casefold check can crash on a negative
dentry (https://sashiko.dev/#/patchset/20260907045517.1347518-1-cui.tao%40linux.dev):

ovl_dentry_casefolded() evaluates IS_CASEFOLDED(d_inode()), which is a
plain dereference, so a negative dentry would crash before we even get
to the WARN_ON(!newdentry->d_inode) check below.  And if it somehow
survived that, ovl_cleanup_locked() would rmdir a negative dentry.

The NULL deref itself is pre-existing (dfc7da402ccc9), but the cleanup
call makes it worse, so I'll fix the ordering in v2:

+			if (!err && d_is_positive(newdentry) &&
+			    ofs->casefold != ovl_dentry_casefolded(newdentry)) {

Negative dentries stay on the existing WARN_ON path.



  reply	other threads:[~2026-09-07  5:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  4:55 [PATCH] ovl: clean up dir on casefold mismatch Tao Cui
2026-09-07  5:37 ` Tao Cui [this message]
2026-09-07 11:08   ` Amir Goldstein

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=73236c69-bd81-45e1-8195-59775a34475a@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=amir73il@gmail.com \
    --cc=andrealmeid@igalia.com \
    --cc=cuitao@kylinos.cn \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=stable@vger.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.