Re: [f2fs-dev] KMSAN: uninit-value in f2fs_lookup

From: Eric Biggers
Date: Fri Sep 25 2020 - 12:38:22 EST


On Fri, Sep 25, 2020 at 05:06:33PM +0800, Chao Yu wrote:
> Hi,
>
> I don't see any problem here, thanks for your report. :)
>
> Thanks,

What about if max_depth == 0 in __f2fs_find_entry()? Then __f2fs_find_entry()
would return NULL without initializing *res_page.

A fix could be:

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 069f498af1e3..ceb4431b5669 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -357,16 +357,15 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
unsigned int max_depth;
unsigned int level;

+ *res_page = NULL;
+
if (f2fs_has_inline_dentry(dir)) {
- *res_page = NULL;
de = f2fs_find_in_inline_dir(dir, fname, res_page);
goto out;
}

- if (npages == 0) {
- *res_page = NULL;
+ if (npages == 0)
goto out;
- }

max_depth = F2FS_I(dir)->i_current_depth;
if (unlikely(max_depth > MAX_DIR_HASH_DEPTH)) {
@@ -377,7 +376,6 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
}

for (level = 0; level < max_depth; level++) {
- *res_page = NULL;
de = find_in_level(dir, level, fname, res_page);
if (de || IS_ERR(*res_page))
break;