* [f2fs-dev] [PATCH] f2fs: fix uninit-value in f2fs_lookup
@ 2020-09-25 15:19 Chao Yu
2020-09-25 17:14 ` Eric Biggers
0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2020-09-25 15:19 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
From: Chao Yu <yuchao0@huawei.com>
As syzbot reported:
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x21c/0x280 lib/dump_stack.c:118
kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:122
__msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:219
f2fs_lookup+0xe05/0x1a80 fs/f2fs/namei.c:503
lookup_open fs/namei.c:3082 [inline]
open_last_lookups fs/namei.c:3177 [inline]
path_openat+0x2729/0x6a90 fs/namei.c:3365
do_filp_open+0x2b8/0x710 fs/namei.c:3395
do_sys_openat2+0xa88/0x1140 fs/open.c:1168
do_sys_open fs/open.c:1184 [inline]
__do_compat_sys_openat fs/open.c:1242 [inline]
__se_compat_sys_openat+0x2a4/0x310 fs/open.c:1240
__ia32_compat_sys_openat+0x56/0x70 fs/open.c:1240
do_syscall_32_irqs_on arch/x86/entry/common.c:80 [inline]
__do_fast_syscall_32+0x129/0x180 arch/x86/entry/common.c:139
do_fast_syscall_32+0x6a/0xc0 arch/x86/entry/common.c:162
do_SYSENTER_32+0x73/0x90 arch/x86/entry/common.c:205
entry_SYSENTER_compat_after_hwframe+0x4d/0x5c
In f2fs_lookup(), @res_page could be used before being initialized,
because in __f2fs_find_entry(), once F2FS_I(dir)->i_current_depth was
been fuzzed to zero, then @res_page will never be initialized, causing
this kmsan warning, relocating @res_page initialization place to fix
this bug.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/dir.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 703cf8e21fc0..83630341ffa3 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)) {
--
2.22.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: fix uninit-value in f2fs_lookup
2020-09-25 15:19 [f2fs-dev] [PATCH] f2fs: fix uninit-value in f2fs_lookup Chao Yu
@ 2020-09-25 17:14 ` Eric Biggers
2020-09-25 23:31 ` Chao Yu
0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2020-09-25 17:14 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel
On Fri, Sep 25, 2020 at 11:19:26PM +0800, Chao Yu wrote:
> From: Chao Yu <yuchao0@huawei.com>
>
> As syzbot reported:
>
> Call Trace:
> __dump_stack lib/dump_stack.c:77 [inline]
> dump_stack+0x21c/0x280 lib/dump_stack.c:118
> kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:122
> __msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:219
> f2fs_lookup+0xe05/0x1a80 fs/f2fs/namei.c:503
> lookup_open fs/namei.c:3082 [inline]
> open_last_lookups fs/namei.c:3177 [inline]
> path_openat+0x2729/0x6a90 fs/namei.c:3365
> do_filp_open+0x2b8/0x710 fs/namei.c:3395
> do_sys_openat2+0xa88/0x1140 fs/open.c:1168
> do_sys_open fs/open.c:1184 [inline]
> __do_compat_sys_openat fs/open.c:1242 [inline]
> __se_compat_sys_openat+0x2a4/0x310 fs/open.c:1240
> __ia32_compat_sys_openat+0x56/0x70 fs/open.c:1240
> do_syscall_32_irqs_on arch/x86/entry/common.c:80 [inline]
> __do_fast_syscall_32+0x129/0x180 arch/x86/entry/common.c:139
> do_fast_syscall_32+0x6a/0xc0 arch/x86/entry/common.c:162
> do_SYSENTER_32+0x73/0x90 arch/x86/entry/common.c:205
> entry_SYSENTER_compat_after_hwframe+0x4d/0x5c
>
> In f2fs_lookup(), @res_page could be used before being initialized,
> because in __f2fs_find_entry(), once F2FS_I(dir)->i_current_depth was
> been fuzzed to zero, then @res_page will never be initialized, causing
> this kmsan warning, relocating @res_page initialization place to fix
> this bug.
>
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
> fs/f2fs/dir.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
> index 703cf8e21fc0..83630341ffa3 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)) {
Can't the assignment to *res_page below be removed too?
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;
}
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: fix uninit-value in f2fs_lookup
2020-09-25 17:14 ` Eric Biggers
@ 2020-09-25 23:31 ` Chao Yu
0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2020-09-25 23:31 UTC (permalink / raw)
To: Eric Biggers; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel
On 2020-9-26 1:14, Eric Biggers wrote:
> On Fri, Sep 25, 2020 at 11:19:26PM +0800, Chao Yu wrote:
>> From: Chao Yu <yuchao0@huawei.com>
>>
>> As syzbot reported:
>>
>> Call Trace:
>> __dump_stack lib/dump_stack.c:77 [inline]
>> dump_stack+0x21c/0x280 lib/dump_stack.c:118
>> kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:122
>> __msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:219
>> f2fs_lookup+0xe05/0x1a80 fs/f2fs/namei.c:503
>> lookup_open fs/namei.c:3082 [inline]
>> open_last_lookups fs/namei.c:3177 [inline]
>> path_openat+0x2729/0x6a90 fs/namei.c:3365
>> do_filp_open+0x2b8/0x710 fs/namei.c:3395
>> do_sys_openat2+0xa88/0x1140 fs/open.c:1168
>> do_sys_open fs/open.c:1184 [inline]
>> __do_compat_sys_openat fs/open.c:1242 [inline]
>> __se_compat_sys_openat+0x2a4/0x310 fs/open.c:1240
>> __ia32_compat_sys_openat+0x56/0x70 fs/open.c:1240
>> do_syscall_32_irqs_on arch/x86/entry/common.c:80 [inline]
>> __do_fast_syscall_32+0x129/0x180 arch/x86/entry/common.c:139
>> do_fast_syscall_32+0x6a/0xc0 arch/x86/entry/common.c:162
>> do_SYSENTER_32+0x73/0x90 arch/x86/entry/common.c:205
>> entry_SYSENTER_compat_after_hwframe+0x4d/0x5c
>>
>> In f2fs_lookup(), @res_page could be used before being initialized,
>> because in __f2fs_find_entry(), once F2FS_I(dir)->i_current_depth was
>> been fuzzed to zero, then @res_page will never be initialized, causing
>> this kmsan warning, relocating @res_page initialization place to fix
>> this bug.
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>> fs/f2fs/dir.c | 7 +++----
>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
>> index 703cf8e21fc0..83630341ffa3 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)) {
>
> Can't the assignment to *res_page below be removed too?
Now I checked all branches in find_in_level(), it looks safe to remove *res_page
assignment in the loop.
Thanks,
>
> 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;
> }
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-25 23:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 15:19 [f2fs-dev] [PATCH] f2fs: fix uninit-value in f2fs_lookup Chao Yu
2020-09-25 17:14 ` Eric Biggers
2020-09-25 23:31 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).