Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2211468iof; Tue, 7 Jun 2022 23:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoPv3XRopjK7P/0cRT7ar/ALYx4CGilZM2sf2wyPgefbFIey+HkG/nG7X5jZzWV3Uv53r0 X-Received: by 2002:a17:90a:bf94:b0:1e2:e640:37dd with SMTP id d20-20020a17090abf9400b001e2e64037ddmr55553454pjs.169.1654669227994; Tue, 07 Jun 2022 23:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654669227; cv=none; d=google.com; s=arc-20160816; b=v7dWgA6AFnfjV0vG2rq5vSSy0VwCSB1OPllQ+kibux1b58rV59ioUlnBszH6/XB4Ef kis9YFYye8EvLjLAlE4VhDvZXbsEsJU1IoWtC7H1+CWEJPWb5u51nRLD1WZwjX2VzSce 5DvgPhPIfgl1gVfLKIrpXzT6PmnuBT+8ByYkj5GGFhG8h7QpwlACi9p5ulUN+7ToW/cj kForBYUlsZvyCaDAxXvmeeLtJBHUgrTor03oO57+o7jflTEkmoK5wuraSfBrFIkox7ig wK+/u11JPXYn2Ue2MIhcWs9wdpRIQZDyszHWIiJAKB2pH6bzzRn8eBcbLhqMc2z9WIqi qw3A== 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=GRP/F9OBJ5+bOOftiBM9Ya8vrFkdtNTdLFiytslhkhI=; b=HoFXVcgQRMPQ+A27tNDbKKm3bh/RTUEQQTE0Eb18f130SANRX1+EDcZ4vC0dvu5Tdv +folCXteeVPHPZkRQ6qg0tujP0wawi2rnZ6b3BQEWc6DPbNY65xycm4Nf5PVtlZyfzT+ /uctes6QA7klUBUJ7o2qOTWkF95cDkklJWzLle6r9T4Y7ABAsk7R9ZWpQm4K3Q/XRqN+ DLu9DzXJERr3HIAoq+EGinD7RvQ5ZP3nQQAIaA1WSNob8aGEkLsRSF/Sk9zAMbdJw4kS S1R2yRyLZY4++heaJCUKoXq6X9S1YK1SJfc2a0lfmshUpzO2Jwo3W7G7d58jLEt8BPAA sX9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SGMyMz/S"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f67-20020a636a46000000b003fcb45d2c86si26620233pgc.485.2022.06.07.23.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:20:27 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SGMyMz/S"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC81539A3FD; Tue, 7 Jun 2022 22:41:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442890AbiFHCBT (ORCPT + 99 others); Tue, 7 Jun 2022 22:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1840083AbiFHAEX (ORCPT ); Tue, 7 Jun 2022 20:04:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5655A6FA33; Tue, 7 Jun 2022 12:18:10 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1327B618EC; Tue, 7 Jun 2022 19:18:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23B53C385A5; Tue, 7 Jun 2022 19:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629488; bh=nq6ivhsF8LEWQhXdFUAKW1Cj0mLljzuni6/4am2Ui/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SGMyMz/SUZnEpvbnvEKsHm8zlXkBvyuBv9zc3rEWZCBOl5gtjogSOBVPxnTtIKIYe lSPOdY+HzVOkLpWXdU3lKInaiqgNPmKW/R+PHy/cyqWdxCSUi8SET3nbW3w9anq3/U h0Rw6LB0mdImEcBFk84uW0M9eXdC0M/oNJR9In4s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ming Yan , Chao Yu , Jaegeuk Kim Subject: [PATCH 5.18 708/879] f2fs: fix to avoid f2fs_bug_on() in dec_valid_node_count() Date: Tue, 7 Jun 2022 19:03:46 +0200 Message-Id: <20220607165023.405500059@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 commit 4d17e6fe9293d57081ffdc11e1cf313e25e8fd9e upstream. As Yanming reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215897 I have encountered a bug in F2FS file system in kernel v5.17. The kernel should enable CONFIG_KASAN=y and CONFIG_KASAN_INLINE=y. You can reproduce the bug by running the following commands: The kernel message is shown below: kernel BUG at fs/f2fs/f2fs.h:2511! Call Trace: f2fs_remove_inode_page+0x2a2/0x830 f2fs_evict_inode+0x9b7/0x1510 evict+0x282/0x4e0 do_unlinkat+0x33a/0x540 __x64_sys_unlinkat+0x8e/0xd0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae The root cause is: .total_valid_block_count or .total_valid_node_count could fuzzed to zero, then once dec_valid_node_count() was called, it will cause BUG_ON(), this patch fixes to print warning info and set SBI_NEED_FSCK into CP instead of panic. Cc: stable@vger.kernel.org Reported-by: Ming Yan Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/f2fs.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2605,11 +2605,17 @@ static inline void dec_valid_node_count( { spin_lock(&sbi->stat_lock); - f2fs_bug_on(sbi, !sbi->total_valid_block_count); - f2fs_bug_on(sbi, !sbi->total_valid_node_count); + if (unlikely(!sbi->total_valid_block_count || + !sbi->total_valid_node_count)) { + f2fs_warn(sbi, "dec_valid_node_count: inconsistent block counts, total_valid_block:%u, total_valid_node:%u", + sbi->total_valid_block_count, + sbi->total_valid_node_count); + set_sbi_flag(sbi, SBI_NEED_FSCK); + } else { + sbi->total_valid_block_count--; + sbi->total_valid_node_count--; + } - sbi->total_valid_node_count--; - sbi->total_valid_block_count--; if (sbi->reserved_blocks && sbi->current_reserved_blocks < sbi->reserved_blocks) sbi->current_reserved_blocks++;