Skip to contentSkip to conversation

f2fs crypto: avoid unneeded memory allocation in ->readdir

PATCH In review Eric Biggers 2 participants 2 messages Oct 31, 2020 – Nov 1, 2020

Subsystems (2)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 f2fs crypto: avoid unneeded memory allocation in ->readdir

From: Chao Yu <[email protected]>

commit e06f86e61d7a67fe6e826010f57aa39c674f4b1b upstream. [This backport fixes a regression in 4.4-stable caused by commit 11a6e8f89521 ("f2fs: check memory boundary by insane namelen"), which depended on this missing commit. This bad backport broke f2fs encryption because it moved the incrementing of 'bit_pos' to earlier in f2fs_fill_dentries() without accounting for it being used in the encrypted dir case. This caused readdir() on encrypted directories to start failing. Tested with 'kvm-xfstests -c f2fs -g encrypt'.]

When decrypting dirents in ->readdir, fscrypt_fname_disk_to_usr won't change content of original encrypted dirent, we don't need to allocate additional buffer for storing mirror of it, so get rid of it.

---
 fs/f2fs/dir.c | 7 -------
 1 file changed, 7 deletions(-)
fs/f2fs/dir.c +0 -7
index e2ff0eb16f89c..c1130914d6ed7 100644
@@ -820,15 +820,8 @@ bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
 			int save_len = fstr->len;
 			int ret;
 
-			de_name.name = kmalloc(de_name.len, GFP_NOFS);
-			if (!de_name.name)
-				return false;
-
-			memcpy(de_name.name, d->filename[bit_pos], de_name.len);
-
 			ret = f2fs_fname_disk_to_usr(d->inode, &de->hash_code,
 							&de_name, fstr);
-			kfree(de_name.name);
 			if (ret < 0)
 				return true;
 
Signature · 1 line
2.29.1
maintainer
#1 lore raw
Quoted 15 lines · Eric Biggers

From: Chao Yu <[email protected]>

commit e06f86e61d7a67fe6e826010f57aa39c674f4b1b upstream. [This backport fixes a regression in 4.4-stable caused by commit 11a6e8f89521 ("f2fs: check memory boundary by insane namelen"), which depended on this missing commit. This bad backport broke f2fs encryption because it moved the incrementing of 'bit_pos' to earlier in f2fs_fill_dentries() without accounting for it being used in the encrypted dir case. This caused readdir() on encrypted directories to start failing. Tested with 'kvm-xfstests -c f2fs -g encrypt'.]

When decrypting dirents in ->readdir, fscrypt_fname_disk_to_usr won't change content of original encrypted dirent, we don't need to allocate additional buffer for storing mirror of it, so get rid of it.

Quoted 6 lines
---
 fs/f2fs/dir.c | 7 -------
 1 file changed, 7 deletions(-)

Now queued up, thanks.

greg k-h