Skip to content

Commit e447d60

Browse files
Jaegeuk Kimpundiramit
authored andcommitted
f2fs: don't allow encrypted operations without keys
commit 363fa4e078cbdc97a172c19d19dc04b41b52ebc8 upstream. This patch fixes the renaming bug on encrypted filenames, which was pointed by (ext4: don't allow encrypted operations without keys) Cc: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 2c4e5c2 commit e447d60

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

fs/f2fs/namei.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,12 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
660660
bool is_old_inline = f2fs_has_inline_dentry(old_dir);
661661
int err = -ENOENT;
662662

663+
if ((f2fs_encrypted_inode(old_dir) &&
664+
!fscrypt_has_encryption_key(old_dir)) ||
665+
(f2fs_encrypted_inode(new_dir) &&
666+
!fscrypt_has_encryption_key(new_dir)))
667+
return -ENOKEY;
668+
663669
if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
664670
!fscrypt_has_permitted_context(new_dir, old_inode)) {
665671
err = -EPERM;
@@ -840,6 +846,12 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
840846
int old_nlink = 0, new_nlink = 0;
841847
int err = -ENOENT;
842848

849+
if ((f2fs_encrypted_inode(old_dir) &&
850+
!fscrypt_has_encryption_key(old_dir)) ||
851+
(f2fs_encrypted_inode(new_dir) &&
852+
!fscrypt_has_encryption_key(new_dir)))
853+
return -ENOKEY;
854+
843855
if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
844856
(old_dir != new_dir) &&
845857
(!fscrypt_has_permitted_context(new_dir, old_inode) ||

0 commit comments

Comments
 (0)