All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: kernel@collabora.com, tytso@mit.edu,
	linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org,
	linux-fsdevel@vger.kernel.org, jaegeuk@kernel.org,
	linux-ext4@vger.kernel.org
Subject: Re: [f2fs-dev] [PATCH 3/7] libfs: Validate negative dentries in case-insensitive directories
Date: Fri, 31 Mar 2023 12:31:13 -0300	[thread overview]
Message-ID: <874jq10wfy.fsf@suse.de> (raw)
In-Reply-To: <20230326044627.GD3390869@ZenIV> (Al Viro's message of "Sun, 26 Mar 2023 05:46:27 +0100")

Al Viro <viro@zeniv.linux.org.uk> writes:

> On Wed, Jun 22, 2022 at 03:45:59PM -0400, Gabriel Krisman Bertazi wrote:
>
>> +static inline int generic_ci_d_revalidate(struct dentry *dentry,
>> +					  const struct qstr *name,
>> +					  unsigned int flags)
>> +{
>> +	int is_creation = flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET);
>> +
>> +	if (d_is_negative(dentry)) {
>> +		const struct dentry *parent = READ_ONCE(dentry->d_parent);
>> +		const struct inode *dir = READ_ONCE(parent->d_inode);
>> +
>> +		if (dir && needs_casefold(dir)) {
>> +			if (!d_is_casefold_lookup(dentry))
>> +				return 0;
>
> 	In which conditions does that happen?

Hi Al,

This can happen right after a case-sensitive directory is converted to
case-insensitive. A previous case-sensitive lookup could have left a
negative dentry in the dcache that we need to reject, because it doesn't
have the same assurance of absence of all-variation of names as a
negative dentry created during a case-insensitive lookup.

>> +			if (is_creation &&
>> +			    (dentry->d_name.len != name->len ||
>> +			     memcmp(dentry->d_name.name, name->name, name->len)))
>> +				return 0;
>> +		}
>> +	}
>> +	return 1;
>> +}
>
> 	Analysis of stability of ->d_name, please.  It's *probably* safe, but
> the details are subtle and IMO should be accompanied by several asserts.
> E.g. "we never get LOOKUP_CREATE in op->intent without O_CREAT in op->open_flag
> for such and such reasons, and we verify that in such and such place"...
>
> 	A part of that would be "the call in lookup_dcache() can only get there
> with non-zero flags when coming from __lookup_hash(), and that has parent locked,
> stabilizing the name; the same goes for the call in __lookup_slow(), with the
> only call chain with possibly non-zero flags is through lookup_slow(), where we
> have the parent locked".  However, lookup_fast() and lookup_open() have the
> flags come from nd->flags, and LOOKUP_CREATE can be found there in several areas.
> I _think_ we are guaranteed the parent locked in all such call chains, but that
> is definitely worth at least a comment.

Thanks for the example of the analysis what you are looking for here.
That will help me quite a bit.  I wrote this code a while ago and I
don't recall the exact details.  I will go through the code again and
send a new version with the detailed analysis.

-- 
Gabriel Krisman Bertazi

WARNING: multiple messages have this Message-ID (diff)
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu,
	linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org,
	linux-fsdevel@vger.kernel.org, jaegeuk@kernel.org,
	kernel@collabora.com
Subject: Re: [f2fs-dev] [PATCH 3/7] libfs: Validate negative dentries in case-insensitive directories
Date: Fri, 31 Mar 2023 12:31:13 -0300	[thread overview]
Message-ID: <874jq10wfy.fsf@suse.de> (raw)
In-Reply-To: <20230326044627.GD3390869@ZenIV> (Al Viro's message of "Sun, 26 Mar 2023 05:46:27 +0100")

Al Viro <viro@zeniv.linux.org.uk> writes:

> On Wed, Jun 22, 2022 at 03:45:59PM -0400, Gabriel Krisman Bertazi wrote:
>
>> +static inline int generic_ci_d_revalidate(struct dentry *dentry,
>> +					  const struct qstr *name,
>> +					  unsigned int flags)
>> +{
>> +	int is_creation = flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET);
>> +
>> +	if (d_is_negative(dentry)) {
>> +		const struct dentry *parent = READ_ONCE(dentry->d_parent);
>> +		const struct inode *dir = READ_ONCE(parent->d_inode);
>> +
>> +		if (dir && needs_casefold(dir)) {
>> +			if (!d_is_casefold_lookup(dentry))
>> +				return 0;
>
> 	In which conditions does that happen?

Hi Al,

This can happen right after a case-sensitive directory is converted to
case-insensitive. A previous case-sensitive lookup could have left a
negative dentry in the dcache that we need to reject, because it doesn't
have the same assurance of absence of all-variation of names as a
negative dentry created during a case-insensitive lookup.

>> +			if (is_creation &&
>> +			    (dentry->d_name.len != name->len ||
>> +			     memcmp(dentry->d_name.name, name->name, name->len)))
>> +				return 0;
>> +		}
>> +	}
>> +	return 1;
>> +}
>
> 	Analysis of stability of ->d_name, please.  It's *probably* safe, but
> the details are subtle and IMO should be accompanied by several asserts.
> E.g. "we never get LOOKUP_CREATE in op->intent without O_CREAT in op->open_flag
> for such and such reasons, and we verify that in such and such place"...
>
> 	A part of that would be "the call in lookup_dcache() can only get there
> with non-zero flags when coming from __lookup_hash(), and that has parent locked,
> stabilizing the name; the same goes for the call in __lookup_slow(), with the
> only call chain with possibly non-zero flags is through lookup_slow(), where we
> have the parent locked".  However, lookup_fast() and lookup_open() have the
> flags come from nd->flags, and LOOKUP_CREATE can be found there in several areas.
> I _think_ we are guaranteed the parent locked in all such call chains, but that
> is definitely worth at least a comment.

Thanks for the example of the analysis what you are looking for here.
That will help me quite a bit.  I wrote this code a while ago and I
don't recall the exact details.  I will go through the code again and
send a new version with the detailed analysis.

-- 
Gabriel Krisman Bertazi


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2023-03-31 15:31 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22 19:45 [PATCH 0/7] Support negative dentries on case-insensitive directories Gabriel Krisman Bertazi
2022-06-22 19:45 ` [f2fs-dev] " Gabriel Krisman Bertazi
2022-06-22 19:45 ` [PATCH 1/7] fs: Expose name under lookup to d_revalidate hook Gabriel Krisman Bertazi
2022-06-22 19:45   ` [f2fs-dev] " Gabriel Krisman Bertazi
2023-03-23 14:33   ` Theodore Ts'o
2023-03-23 14:33     ` [f2fs-dev] " Theodore Ts'o
2023-03-25 13:33     ` Theodore Ts'o
2023-03-25 13:33       ` [f2fs-dev] " Theodore Ts'o
2023-03-26  5:03       ` Al Viro
2023-03-26  5:03         ` [f2fs-dev] " Al Viro
2022-06-22 19:45 ` [PATCH 2/7] fs: Add DCACHE_CASEFOLD_LOOKUP flag Gabriel Krisman Bertazi
2022-06-22 19:45   ` [f2fs-dev] " Gabriel Krisman Bertazi
2023-03-23 14:33   ` Theodore Ts'o
2023-03-23 14:33     ` [f2fs-dev] " Theodore Ts'o
2022-06-22 19:45 ` [PATCH 3/7] libfs: Validate negative dentries in case-insensitive directories Gabriel Krisman Bertazi
2022-06-22 19:45   ` [f2fs-dev] " Gabriel Krisman Bertazi
2023-03-23 14:36   ` Theodore Ts'o
2023-03-23 14:36     ` [f2fs-dev] " Theodore Ts'o
2023-03-26  4:46   ` Al Viro
2023-03-26  4:46     ` [f2fs-dev] " Al Viro
2023-03-31 15:31     ` Gabriel Krisman Bertazi [this message]
2023-03-31 15:31       ` Gabriel Krisman Bertazi
2022-06-22 19:46 ` [PATCH 4/7] libfs: Support revalidation of encrypted case-insensitive dentries Gabriel Krisman Bertazi
2022-06-22 19:46   ` [f2fs-dev] " Gabriel Krisman Bertazi
2023-03-23 14:37   ` Theodore Ts'o
2023-03-23 14:37     ` [f2fs-dev] " Theodore Ts'o
2022-06-22 19:46 ` [PATCH 5/7] libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops Gabriel Krisman Bertazi
2022-06-22 19:46   ` [f2fs-dev] " Gabriel Krisman Bertazi
2023-03-23 14:39   ` Theodore Ts'o
2023-03-23 14:39     ` [f2fs-dev] " Theodore Ts'o
2022-06-22 19:46 ` [PATCH 6/7] ext4: Enable negative dentries on case-insensitive lookup Gabriel Krisman Bertazi
2022-06-22 19:46   ` [f2fs-dev] " Gabriel Krisman Bertazi
2022-06-23  7:29   ` kernel test robot
2022-06-23  7:29     ` [f2fs-dev] " kernel test robot
2022-06-23 16:36     ` Gabriel Krisman Bertazi
2022-06-23 16:36       ` Gabriel Krisman Bertazi
2022-06-23 16:36       ` [f2fs-dev] " Gabriel Krisman Bertazi
2023-03-23 14:39   ` Theodore Ts'o
2023-03-23 14:39     ` [f2fs-dev] " Theodore Ts'o
2022-06-22 19:46 ` [PATCH 7/7] f2fs: " Gabriel Krisman Bertazi
2022-06-22 19:46   ` [f2fs-dev] " Gabriel Krisman Bertazi
2022-06-23 12:44   ` kernel test robot
2022-06-23 12:44     ` [f2fs-dev] " kernel test robot
2023-02-24 22:36 ` [PATCH 0/7] Support negative dentries on case-insensitive directories Daniel Rosenberg
2023-02-24 22:36   ` [f2fs-dev] " Daniel Rosenberg via Linux-f2fs-devel

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=874jq10wfy.fsf@suse.de \
    --to=krisman@suse.de \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=kernel@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 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.