mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sarthak Kukreti <sarthakkukreti@google.com>
To: Gabriel Krisman Bertazi <krisman@suse.de>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Eric Biggers <ebiggers@kernel.org>
Cc: Sarthak Kukreti <sarthakkukreti@google.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>,  Chao Yu <chao@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	 Christian Brauner <brauner@kernel.org>,
	Dmitry Torokhov <dtor@google.com>,
	linux-fsdevel@vger.kernel.org,  linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] libfs: reject casefolded names that fold to ".", "..", or empty
Date: Mon, 16 Nov 2026 18:44:44 -0800	[thread overview]
Message-ID: <20261117024444.2653745-1-sarthakkukreti@google.com> (raw)
In-Reply-To: <878q2swoxp.fsf@cartola>

On Mon, Nov 16, 2026 at 02:34:26PM -0500, Gabriel Krisman Bertazi wrote:
> Ugh. I agree this is a problem, but I'm also trying to understand first
> the real impact beyond filesystem complaints during lookup, if any:
>
>   1. Looking up ".\u202e" folds to "." and matches the on-disk "." entry
>      (de->inode == dir->i_ino) in generic_ci_match(), triggering
>      EXT4_ERROR_INODE ("linked to parent dir") in ext4_lookup().
>   2. Looking up "..\u202e" folds to ".." and matches the on-disk ".."
>      entry, returning -ELOOP via d_splice_alias() (or triggering
>      EXT4_ERROR_INODE on the root directory).
>
> These two look like a "do stupid things, get stupid prizes" with no
> further repercussions beyond the error message.  Sure, we can fix them
> to throw EINVAL, but are there bigger repercussions I'm missing?

In addition to what Eric mentioned re: side-effects due to
errors=remount-ro and errors=panic, encountering EXT4_ERROR_INODE marks
the superblock with an error flag which can trigger a full fsck pass on
the next boot.

>   3. Filenames consisting solely of ignorable characters fold to "" (0
>      bytes), causing distinct ignorable-only filenames to hash and compare
>      equal and creating entries that e2fsck flags as corruption.
>
> This seems concerning. Do we actually writes multiple files to the disk?
> shouldn't they all be folded into the same empty string and rejected or
> at least written as a single file?  I'm not sure how it'd be writing
> multiple files to the disk, that seems like a bigger problem.

Sorry, that should have been specifically for f2fs: ext4 will only write
the first ignorable-only file to disk and subsequent files fail with
-EEXIST. On f2fs, f2fs_init_casefolded_name() treats `len <= 0` as a
fallback to raw bytewise hashing/matching, which allows multiple
ignorable-only files to be written to disk (which fsck.f2fs then flags
with hash mismatches).

> > Fixes: c843843e714c ("fs: Add standard casefolding support")
>
> This bug was just made generic by c843843e714c, but the issue was
> introduced by b886ee3e778e in ext4 and the equivalent f2fs support.

Ack, I will update the Fixes tags in v2.

> > +	if (name_is_dot_dotdot(str, len) ||
> > +	    name_is_dot_dotdot(name->name, name->len))
> > +		return 1;
>
> This is checking for strictly encoded '.' and '..'.  But I'm not sure
> that happens? Do we really reach the dcache for '.' and '..' instead of
> the name of the parent or cwd?
>
> > +	um = dentry->d_sb->s_encoding;
> > +	cf_len = utf8_casefold(um, name, buf, sizeof(buf));
> > +	if (cf_len == 0 || (cf_len > 0 && name_is_dot_dotdot(buf, cf_len)))
> > +		return 1;
>
> I think this is a bit too late in the lookup to detect these
> code-points.  I'd much rather we fail the lookup outright instead of
> attempting to treat them as different spellings of . and .. . But isn't
> this dead code because we are rejecting those strings in d_hash through
> your hunk below?  Is there a way we get here without the -EINVAL in
> d_hash first?

Ah right - let me get rid of this for v2.

> But the way I'd suggest be handled is by rejecting the ignorable code
> points lookup (all, but variant selectors for the reasons above), early
> in the lookup path for case-insensitive directories so they never even
> get to the filesystem.  Wdyt?

As Eric pointed out, since variation selectors are also
Default_Ignorable_Code_Point and stripped to 0 bytes by utf8_casefold(),
allowing variation selectors means names like ".\ufe00", "..\ufe00", and
"\ufe00" still fold to ".", "..", and "" and hit the exact same bug.

Thanks,
Sarthak

  parent reply	other threads:[~2026-11-17  2:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  6:53 [PATCH 0/3] fs: " Sarthak Kukreti
2026-11-13  6:53 ` [PATCH 1/3] libfs: " Sarthak Kukreti
2026-11-16 19:34   ` Gabriel Krisman Bertazi
2026-11-16 20:05     ` Eric Biggers
2026-11-17  2:00     ` Theodore Tso
2026-11-17  8:47       ` David Laight
2026-11-17  2:44     ` Sarthak Kukreti [this message]
2026-11-13  6:53 ` [PATCH 2/3] ext4: " Sarthak Kukreti
2026-11-13  6:53 ` [PATCH 3/3] f2fs: " Sarthak Kukreti

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=20261117024444.2653745-1-sarthakkukreti@google.com \
    --to=sarthakkukreti@google.com \
    --cc=brauner@kernel.org \
    --cc=chao@kernel.org \
    --cc=dtor@google.com \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=krisman@suse.de \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®