Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3438065pxk; Mon, 28 Sep 2020 18:27:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycOHka4e9vDJxmnu6+pim5ZHdpJQU9saSpM2R4yy40xDo2PNI8hPuVOQWiPQXVU3h31Mbp X-Received: by 2002:a17:906:7f15:: with SMTP id d21mr1544675ejr.470.1601342853729; Mon, 28 Sep 2020 18:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601342853; cv=none; d=google.com; s=arc-20160816; b=rfrkTK1QjNvzsUy4moMWuG44vCDg1+jlk5HGuNb7oVDHom6bgcWB8rKvjmzYwm4Jda pCVEc3vZ84MbWJ0IWZqEbGkqpRyD2OgKfOc/t13BdIlE8kAeUJJOMJr/n605vG7xYxgx Vp53uJNE9AzXgNcWMz0P7J0K5Kfb1eMixoPiWjoy2IUpDRRJVLpeAVPeKgQcN584dpBc /OIkHuQBx9gL2GH5ormmh9me8SaMGf49YWbh+TwRgLxBXzv+LSN16ADLsg6DCXClQEQj RKswowowhVEUzndqRPlBsf5QzzFx9hxLB5Fg2g+XyZDSOiYUCEmijJSGgB98ipZmZqsR KWvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=u1piWyiT22OV5u8tMcDXmAUZ3K/OJZ88+0nfsWHpjxI=; b=SvuGuRtRoW5LI+nHlfXj5+kYldstYHswvarR0YzgvItzynOvMZPly2UQItKlwXo+WJ oS+e//EYcnLQE/rEw3Bp9QI+Reyqsqgm/FzxzIgc2nk562EYHnH+nkzwRLBQR3Kcs/3q 5fxHzHiq7nnNEGUw8J53umbzw+uCd/wqf2RnztozSjqqgjvqNdRCuGuiRKZq4/ts2zNE OMJhDMexjI8kgf4nbdsysNCM8ik3LQLjtuclSZmMkaaxdI6+q+lTAfPzQcTkCMddAJX/ hj4MoBR3BjMOuWIC0DXmcsDeSCVsu3yAz2UFq9OeabN3DvvZa3kHSJFLbNekdFSTmbvQ MioQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si1653278ejd.442.2020.09.28.18.27.07; Mon, 28 Sep 2020 18:27:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbgI2BXI (ORCPT + 99 others); Mon, 28 Sep 2020 21:23:08 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14764 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725272AbgI2BXI (ORCPT ); Mon, 28 Sep 2020 21:23:08 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AF77482D33A4B3447144; Tue, 29 Sep 2020 09:23:05 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Tue, 29 Sep 2020 09:22:56 +0800 From: Chao Yu To: CC: , , , Chao Yu , Subject: [PATCH v3] f2fs: fix uninit-value in f2fs_lookup Date: Tue, 29 Sep 2020 09:22:50 +0800 Message-ID: <20200929012250.109536-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reported-by: syzbot+0eac6f0bbd558fd866d7@syzkaller.appspotmail.com Signed-off-by: Chao Yu --- v3: - add reported-by tag. fs/f2fs/dir.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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; -- 2.26.2