Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3309229rwa; Tue, 23 Aug 2022 02:30:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR6s5dObWaNb+mPL10HOFzXZs8igqxoDmWwbiRlB3UziqZwRtZgvURhUF0DGTvC1WVUpK3wJ X-Received: by 2002:a05:6402:11c8:b0:440:6513:be2c with SMTP id j8-20020a05640211c800b004406513be2cmr2865071edw.45.1661247000492; Tue, 23 Aug 2022 02:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661247000; cv=none; d=google.com; s=arc-20160816; b=Fk/S+FLdqI3bNxkY3UtGI/NcSgLZ23R3anUEqlWJ77zaw9/Rj98FWsV6/CKv9zKN0Q zBzR7dXvDBigVUA7yot35aDD9v5B+ueeUV1i3cJ6XlgG5uu0iVHYAMDN0LZP+MoKiJ6D 7SH2SLDa/ib641tCHXZBA0yW3fsyjn8mLUwKS/QVSFdXGU4vfwvRQHCnVrHup2Hewwfe H++LHiQdL0Za0+c+3yVEmVVydm/u3wzf4EUeYHfCrHVii4w6fOcQHO0TS4PFdy0N6RzM aVkzBEyvDRpRxUShuhHwVxF4hOCXSf+wZhVE5KZ2RV6Egf7jIJh3RieWUAotci60nfkr NtqA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rNcC6l11v1+jhhCIUrEVCFIghQqroyzmwN9mOrf4/v8=; b=nWIDXAaswGcKTIxOJiBqYvSBxHJ3e6i1gildHcHSEg3Ca7efZGHzlfJwwWS55Jnv+C mmaHCj9/rwY+EN7Gd0tNszq/zVxv+bRLEoErweEoNCJck67ojN9RK5AVjWtfRUZ2gB42 faJh+esD4ZVd4rLf0bfb86PDYBtvJmdGQ45HW8/h8Hyi4N1uGHgHA9/ZddMqQM1hH3wx GTYNWIhnxYcHked7Zvz/RUyfrTVyzW5B+UKWb5vxXFsTxSFH8rKaBDEl/DECqEGzzF+a b72VnAjPRqv0+el7njUoDtF2diDRQN8qGlt3/4derO/jrdVG78ndPzf2MkEiFjPjDHCQ MY6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qjdk537X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn30-20020a1709070d1e00b0073d6590a430si7920658ejc.382.2022.08.23.02.29.34; Tue, 23 Aug 2022 02:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qjdk537X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350049AbiHWJ1y (ORCPT + 99 others); Tue, 23 Aug 2022 05:27:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350014AbiHWJZD (ORCPT ); Tue, 23 Aug 2022 05:25:03 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92C0B760D2; Tue, 23 Aug 2022 01:36:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 332D5CE1B44; Tue, 23 Aug 2022 08:34:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26B4CC433C1; Tue, 23 Aug 2022 08:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243684; bh=Ubdo+zLeCBEUIp0Fs/1zOYCZvfQ0W+LWuOA/P/mTFU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qjdk537XAETYkReiURImRW1LWfq4Z8Dwjd4TyS4ezHWnaDBUScrF94kbz9Zx83tvm U6Gb8lmQjEs0fkDYTe0HqkMOP3ISwM2bocUAQkuYGYCd8/dZhIsVaNHemcJYsm7Efp 6zZYKTWUsbukLOaNDXTd+55xr3oJ0MFUz4aGnyqY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dipanjan Das , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.19 355/365] f2fs: fix to avoid use f2fs_bug_on() in f2fs_new_node_page() Date: Tue, 23 Aug 2022 10:04:16 +0200 Message-Id: <20220823080133.124438091@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Yu [ Upstream commit 141170b759e03958f296033bb7001be62d1d363b ] As Dipanjan Das reported, syzkaller found a f2fs bug as below: RIP: 0010:f2fs_new_node_page+0x19ac/0x1fc0 fs/f2fs/node.c:1295 Call Trace: write_all_xattrs fs/f2fs/xattr.c:487 [inline] __f2fs_setxattr+0xe76/0x2e10 fs/f2fs/xattr.c:743 f2fs_setxattr+0x233/0xab0 fs/f2fs/xattr.c:790 f2fs_xattr_generic_set+0x133/0x170 fs/f2fs/xattr.c:86 __vfs_setxattr+0x115/0x180 fs/xattr.c:182 __vfs_setxattr_noperm+0x125/0x5f0 fs/xattr.c:216 __vfs_setxattr_locked+0x1cf/0x260 fs/xattr.c:277 vfs_setxattr+0x13f/0x330 fs/xattr.c:303 setxattr+0x146/0x160 fs/xattr.c:611 path_setxattr+0x1a7/0x1d0 fs/xattr.c:630 __do_sys_lsetxattr fs/xattr.c:653 [inline] __se_sys_lsetxattr fs/xattr.c:649 [inline] __x64_sys_lsetxattr+0xbd/0x150 fs/xattr.c:649 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 NAT entry and nat bitmap can be inconsistent, e.g. one nid is free in nat bitmap, and blkaddr in its NAT entry is not NULL_ADDR, it may trigger BUG_ON() in f2fs_new_node_page(), fix it. Reported-by: Dipanjan Das Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/node.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index cf6f7fc83c08..02e92a72511b 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1292,7 +1292,11 @@ struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs) dec_valid_node_count(sbi, dn->inode, !ofs); goto fail; } - f2fs_bug_on(sbi, new_ni.blk_addr != NULL_ADDR); + if (unlikely(new_ni.blk_addr != NULL_ADDR)) { + err = -EFSCORRUPTED; + set_sbi_flag(sbi, SBI_NEED_FSCK); + goto fail; + } #endif new_ni.nid = dn->nid; new_ni.ino = dn->inode->i_ino; -- 2.35.1