Message ID | 20220511193146.27526-6-krisman@collabora.com |
---|---|
State | Superseded |
Headers | show |
Series | Clean up the case-insensitive lookup path | expand |
On Wed, May 11, 2022 at 03:31:41PM -0400, Gabriel Krisman Bertazi wrote: > The existence of fname->cf_name.name requires s_encoding & IS_CASEFOLDED, > therefore this can be simplified. > > Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> > --- > fs/ext4/namei.c | 20 +++++++------------- > 1 file changed, 7 insertions(+), 13 deletions(-) > > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 5296ced2e43e..cebbcabf0ff0 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -1438,25 +1438,19 @@ static bool ext4_match(struct inode *parent, > #endif > > #if IS_ENABLED(CONFIG_UNICODE) > - if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) && > - (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { > + if (IS_ENCRYPTED(parent) && fname->cf_name.name) { > + if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || > + fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de)) > + return false; > + } > + > + if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent)) { > struct unicode_name u = { > .folded_name = &fname->cf_name, > .usr_name = fname->usr_fname > }; > int ret; > > - if (fname->cf_name.name) { > - if (IS_ENCRYPTED(parent)) { > - if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || > - fname->hinfo.minor_hash != > - EXT4_DIRENT_MINOR_HASH(de)) { > - > - return false; > - } > - } > - } > - I don't think it's correct to delete the check for the encryption key here. If lookup is by no-key name, then fscrypt_match_name() must be used, not generic_ci_match(). And unlike f2fs, ext4 doesn't keep track of whether the whole lookup is by no-key name; ext4 relies on this fscrypt_has_encryption_key() check at the last minute when doing each individual comparison. (Which is not great, but that's how it works now.) - Eric
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 5296ced2e43e..cebbcabf0ff0 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1438,25 +1438,19 @@ static bool ext4_match(struct inode *parent, #endif #if IS_ENABLED(CONFIG_UNICODE) - if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) && - (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { + if (IS_ENCRYPTED(parent) && fname->cf_name.name) { + if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || + fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de)) + return false; + } + + if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent)) { struct unicode_name u = { .folded_name = &fname->cf_name, .usr_name = fname->usr_fname }; int ret; - if (fname->cf_name.name) { - if (IS_ENCRYPTED(parent)) { - if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || - fname->hinfo.minor_hash != - EXT4_DIRENT_MINOR_HASH(de)) { - - return false; - } - } - } - ret = ext4_match_ci(parent, &u, de->name, de->name_len); if (ret < 0) { /*
The existence of fname->cf_name.name requires s_encoding & IS_CASEFOLDED, therefore this can be simplified. Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> --- fs/ext4/namei.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)