linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Gabriel Krisman Bertazi <krisman@suse.de>
Cc: ebiggers@kernel.org, viro@zeniv.linux.org.uk, tytso@mit.edu,
	 linux-fsdevel@vger.kernel.org, jaegeuk@kernel.org
Subject: Re: [PATCH v4] libfs: Attempt exact-match comparison first during casefolded lookup
Date: Wed, 24 Jan 2024 10:42:51 -0800	[thread overview]
Message-ID: <CAHk-=wi9MDF97MGwJv_2V5QLE=f6ShgfKWUPomVKsCKYmAU9XQ@mail.gmail.com> (raw)
In-Reply-To: <87ttn2sip7.fsf_-_@mailhost.krisman.be>

On Wed, 24 Jan 2024 at 10:13, Gabriel Krisman Bertazi <krisman@suse.de> wrote:
>
> Just for completeness, below the version I intend to apply to
> unicode/for-next , which is the v2, plus the comments you and Eric
> requested. That is, unless something else comes up.

Looks ok to me.

My one comment is actually unrelated to the new code, just because the
patch touches this code too:

>         if (len <= DNAME_INLINE_LEN - 1) {
>                 memcpy(strbuf, str, len);
>                 strbuf[len] = 0;
> -               qstr.name = strbuf;
> +               str = strbuf;
>                 /* prevent compiler from optimizing out the temporary buffer */
>                 barrier();

The reason for this whole mess is that allegedly utf8_strncasecmp() is
not safe if the buffer changes under it.

At least that's what the comment says.

But honestly, I don't see it.

I think the whole "copy to a stable buffer" code can and should just
be removed as voodoo programming.

*If* the buffer is actually changing, the name lookup code will just
retry, so whether the return value is correct or not is irrelevant.

All that matters is that the code honors the str/len constraint, and
not blow up - even if the data inside that str/len buffer might not be
stable.

I don't see how the utf8 code could possibly mess up.

That code goes back to commit

  2ce3ee931a09 ("ext4: avoid utf8_strncasecmp() with unstable name")
  fc3bb095ab02 ("f2fs: avoid utf8_strncasecmp() with unstable name")

and I think it's bogus.

Eric - the string *data* may be unsafe, but the string length passed
to the utf8 routines is not changing any more (since it was loaded
long ago).

And honestly, no amount of "the data may change" should possibly ever
cause the utf8 code to then ignore the length that was passed in.

                Linus

  reply	other threads:[~2024-01-24 18:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 20:25 [PATCH v3 0/2] Try exact-match comparison ahead of case-insensitive match Gabriel Krisman Bertazi
2024-01-19 20:25 ` [PATCH v3 1/2] dcache: Expose dentry_string_cmp outside of dcache Gabriel Krisman Bertazi
2024-01-19 20:48   ` Linus Torvalds
2024-01-21 16:34     ` Gabriel Krisman Bertazi
2024-01-21 19:09       ` Linus Torvalds
2024-01-24 18:13         ` [PATCH v4] libfs: Attempt exact-match comparison first during casefolded lookup Gabriel Krisman Bertazi
2024-01-24 18:42           ` Linus Torvalds [this message]
2024-01-24 22:44             ` Eric Biggers
2024-01-19 20:25 ` [PATCH v3 2/2] libfs: Attempt exact-match comparison first during casefold lookup Gabriel Krisman Bertazi

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='CAHk-=wi9MDF97MGwJv_2V5QLE=f6ShgfKWUPomVKsCKYmAU9XQ@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=krisman@suse.de \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).