Skip to content

Commit 63e7f12

Browse files
drosen-googletytso
authored andcommitted
ext4: fix no-key deletion for encrypt+casefold
commit 471fbbe ("ext4: handle casefolding with encryption") is missing a few checks for the encryption key which are needed to support deleting enrypted casefolded files when the key is not present. This bug made it impossible to delete encrypted+casefolded directories without the encryption key, due to errors like: W : EXT4-fs warning (device vdc): __ext4fs_dirhash:270: inode #49202: comm Binder:378_4: Siphash requires key Repro steps in kvm-xfstests test appliance: mkfs.ext4 -F -E encoding=utf8 -O encrypt /dev/vdc mount /vdc mkdir /vdc/dir chattr +F /vdc/dir keyid=$(head -c 64 /dev/zero | xfs_io -c add_enckey /vdc | awk '{print $NF}') xfs_io -c "set_encpolicy $keyid" /vdc/dir for i in `seq 1 100`; do mkdir /vdc/dir/$i done xfs_io -c "rm_enckey $keyid" /vdc rm -rf /vdc/dir # fails with the bug Fixes: 471fbbe ("ext4: handle casefolding with encryption") Signed-off-by: Daniel Rosenberg <drosen@google.com> Link: https://lore.kernel.org/r/20210522004132.2142563-1-drosen@google.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent afd09b6 commit 63e7f12

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/ext4/namei.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,8 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
13761376
struct dx_hash_info *hinfo = &name->hinfo;
13771377
int len;
13781378

1379-
if (!IS_CASEFOLDED(dir) || !dir->i_sb->s_encoding) {
1379+
if (!IS_CASEFOLDED(dir) || !dir->i_sb->s_encoding ||
1380+
(IS_ENCRYPTED(dir) && !fscrypt_has_encryption_key(dir))) {
13801381
cf_name->name = NULL;
13811382
return 0;
13821383
}
@@ -1427,7 +1428,8 @@ static bool ext4_match(struct inode *parent,
14271428
#endif
14281429

14291430
#ifdef CONFIG_UNICODE
1430-
if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent)) {
1431+
if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) &&
1432+
(!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) {
14311433
if (fname->cf_name.name) {
14321434
struct qstr cf = {.name = fname->cf_name.name,
14331435
.len = fname->cf_name.len};

0 commit comments

Comments
 (0)