Skip to contentSkip to conversation

ext4: Correct dentry name hash when readdir with encrypted and not casefolded

PATCH Applied yao.ly 2 participants 2 messages Jul 1, 2024 – Aug 22, 2024 ext4 file system

lore
Share & tools
lore

yao.ly

author
#0 lore raw

PATCH 1/1 ext4: Correct dentry name hash when readdir with encrypted and not casefolded

EXT4_DIRENT_HASH and EXT4_DIRENT_MINOR_HASH will access struct ext4_dir_entry_hash followed ext4_dir_entry. But there is no ext4_dir_entry_hash followed when inode is encrypted and not casefolded

---
 fs/ext4/dir.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
fs/ext4/dir.c +11 -3
index ff4514e..b8b6b06 100644
@@ -279,12 +279,20 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
 					struct fscrypt_str de_name =
 							FSTR_INIT(de->name,
 								de->name_len);
+					u32 hash;
+					u32 minor_hash;
+
+					if (IS_CASEFOLDED(inode)) {
+						hash = EXT4_DIRENT_HASH(de);
+						minor_hash = EXT4_DIRENT_MINOR_HASH(de);
+					} else {
+						hash = 0;
+						minor_hash = 0;
+					}
 
 					/* Directory is encrypted */
 					err = fscrypt_fname_disk_to_usr(inode,
-						EXT4_DIRENT_HASH(de),
-						EXT4_DIRENT_MINOR_HASH(de),
-						&de_name, &fstr);
+						hash, minor_hash, &de_name, &fstr);
 					de_name = fstr;
 					fstr.len = save_len;
 					if (err)
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw
Quoted 5 lines · yao.ly

EXT4_DIRENT_HASH and EXT4_DIRENT_MINOR_HASH will access struct ext4_dir_entry_hash followed ext4_dir_entry. But there is no ext4_dir_entry_hash followed when inode is encrypted and not casefolded

Applied, thanks!

[1/1] ext4: Correct dentry name hash when readdir with encrypted and not casefolded

      commit: 95525bf5b13d28d55fb61400c9e97db6ea7da5f4

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>