From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Eric Biggers <ebiggers@kernel.org>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, tytso@mit.edu,
jaegeuk@kernel.org, linux-fsdevel@vger.kernel.org,
linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
Gabriel Krisman Bertazi <krisman@collabora.com>
Subject: Re: [PATCH v5 06/10] libfs: Validate negative dentries in case-insensitive directories
Date: Mon, 14 Aug 2023 10:50:13 -0400 [thread overview]
Message-ID: <87a5ut7k62.fsf@suse.de> (raw)
In-Reply-To: <20230812024145.GD971@sol.localdomain> (Eric Biggers's message of "Fri, 11 Aug 2023 19:41:45 -0700")
Eric Biggers <ebiggers@kernel.org> writes:
> On Fri, Aug 11, 2023 at 08:41:42PM -0400, Gabriel Krisman Bertazi wrote:
>> + /*
>> + * Filesystems will call into d_revalidate without setting
>> + * LOOKUP_ flags even for file creation (see lookup_one*
>> + * variants). Reject negative dentries in this case, since we
>> + * can't know for sure it won't be used for creation.
>> + */
>> + if (!flags)
>> + return 0;
>> +
>> + /*
>> + * If the lookup is for creation, then a negative dentry can
>> + * only be reused if it's a case-sensitive match, not just a
>> + * case-insensitive one. This is needed to make the new file be
>> + * created with the name the user specified, preserving case.
>> + */
>> + if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) {
>> + /*
>> + * ->d_name won't change from under us in the creation
>> + * path only, since d_revalidate during creation and
>> + * renames is always called with the parent inode
>> + * locked. It isn't the case for all lookup callpaths,
>> + * so ->d_name must not be touched outside
>> + * (LOOKUP_CREATE|LOOKUP_RENAME_TARGET) context.
>> + */
>> + if (dentry->d_name.len != name->len ||
>> + memcmp(dentry->d_name.name, name->name, name->len))
>> + return 0;
>> + }
>
> This is still really confusing to me. Can you consider the below? The code is
> the same except for the reordering, but the explanation is reworked to be much
> clearer (IMO). Anything I am misunderstanding?
>
> /*
> * If the lookup is for creation, then a negative dentry can only be
> * reused if it's a case-sensitive match, not just a case-insensitive
> * one. This is needed to make the new file be created with the name
> * the user specified, preserving case.
> *
> * LOOKUP_CREATE or LOOKUP_RENAME_TARGET cover most creations. In these
> * cases, ->d_name is stable and can be compared to 'name' without
> * taking ->d_lock because the caller holds dir->i_rwsem for write.
> * (This is because the directory lock blocks the dentry from being
> * concurrently instantiated, and negative dentries are never moved.)
> *
> * All other creations actually use flags==0. These come from the edge
> * case of filesystems calling functions like lookup_one() that do a
> * lookup without setting the lookup flags at all. Such lookups might
> * or might not be for creation, and if not don't guarantee stable
> * ->d_name. Therefore, invalidate all negative dentries when flags==0.
> */
> if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) {
> if (dentry->d_name.len != name->len ||
> memcmp(dentry->d_name.name, name->name, name->len))
> return 0;
> }
> if (!flags)
> return 0;
I don't see it as particularly better or less confusing than the
original. but I also don't mind taking it into the next iteration.
--
Gabriel Krisman Bertazi
next prev parent reply other threads:[~2023-08-14 14:51 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-12 0:41 [PATCH v5 00/10] Support negative dentries on case-insensitive ext4 and f2fs Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 01/10] fs: Expose helper to check if a directory needs casefolding Gabriel Krisman Bertazi
2023-08-12 1:59 ` Eric Biggers
2023-08-12 23:06 ` Theodore Ts'o
2023-08-13 0:12 ` Eric Biggers
2023-08-13 3:08 ` Matthew Wilcox
2023-08-13 4:30 ` Eric Biggers
2023-08-14 11:38 ` Theodore Ts'o
2023-08-14 17:22 ` Eric Biggers
2023-08-15 3:59 ` Theodore Ts'o
2023-08-14 15:02 ` Gabriel Krisman Bertazi
2023-08-14 19:14 ` Eric Biggers
2023-08-14 19:26 ` Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 02/10] ecryptfs: Reject casefold directory inodes Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 03/10] 9p: Split ->weak_revalidate from ->revalidate Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 04/10] fs: Expose name under lookup to d_revalidate hooks Gabriel Krisman Bertazi
2023-08-12 2:15 ` Eric Biggers
2023-08-17 7:00 ` kernel test robot
2023-08-17 9:12 ` kernel test robot
2023-08-12 0:41 ` [PATCH v5 05/10] fs: Add DCACHE_CASEFOLDED_NAME flag Gabriel Krisman Bertazi
2023-08-12 2:17 ` Eric Biggers
2023-08-14 15:03 ` Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 06/10] libfs: Validate negative dentries in case-insensitive directories Gabriel Krisman Bertazi
2023-08-12 2:41 ` Eric Biggers
2023-08-14 14:50 ` Gabriel Krisman Bertazi [this message]
2023-08-14 18:42 ` Eric Biggers
2023-08-14 19:21 ` Gabriel Krisman Bertazi
2023-08-14 19:26 ` Eric Biggers
2023-08-12 0:41 ` [PATCH v5 07/10] libfs: Chain encryption checks after case-insensitive revalidation Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 08/10] libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 09/10] ext4: Enable negative dentries on case-insensitive lookup Gabriel Krisman Bertazi
2023-08-12 0:41 ` [PATCH v5 10/10] f2fs: " 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=87a5ut7k62.fsf@suse.de \
--to=krisman@suse.de \
--cc=brauner@kernel.org \
--cc=ebiggers@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=krisman@collabora.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--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