From patchwork Wed Apr 5 14:45:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 79798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp443384vqo; Wed, 5 Apr 2023 09:39:09 -0700 (PDT) X-Google-Smtp-Source: AKy350b60UrOyqfajLlnmf3BoKlzFWHtPpT0WE/QK087ypND6hxa6Qi50khHs9XuRaPEIifR14Vs X-Received: by 2002:a05:6a20:6d87:b0:da:a6ef:5344 with SMTP id gl7-20020a056a206d8700b000daa6ef5344mr6528585pzb.21.1680712749227; Wed, 05 Apr 2023 09:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680712749; cv=none; d=google.com; s=arc-20160816; b=uIPsvQxiSC4xKdhjdY4w1FLSrSefuFNMATfOiBKrcoNEhDlF8DiLs4H6vmupe1bdhO mKfwhdwxWzGSjqktwCcEwvLUvM24G8QtgdpftjBmxd3qBPr9Fzd4zucaNAr/uPt+HdLR jrDC/a99U1bIMu6g/HEdq0CW6XS7N8lGaIpDYwp0IVzmxXR24mMmlccTe8hQqHJAxPbv 0CgS9YpVu9MdYCgoGUyHqXouwOUlLTzbRq2iue/TweQll2lKHRUGzIVqIslZc9h0V3CF BkdHzGmpJ6wIHI+JJPMIVzOit1zgE3rhvHnv9f1g2s/rEWNx6ktpFMQLGs+rFIu5AJy6 C1cg== 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:dkim-signature; bh=33MXYDDb4OYTdD203d6enmcAPUh147sgohZ6lL/hbyA=; b=B+opZHYxL0U232mbwm8gaTx8W6abZc/L0ZXXrnVimBXYcSkEAN3QAHedPro5ouUf/O fnbeSXtzSRhv+Aq+Q3l4HLeXO8Tb76ZcmsZZm8m3fuQyA16bDrbWVhZOVfvycXTz90r5 vqDzq04rVX5nzCGDflRrcTSzsGK7pFsMCu4Exzc3Qaa46HH6e91LExlR1upxG77lYLpp SpVzMM3ixZoON1EWDVJ+K3QJ7sv+CP8MMVtTDimWCt15ieYUfdMfcb78Oq66CdKmLK2K 2Bdgu0avfWS3IsomgJl5R8ErH5Qr3P7siju5KYL8BBTiogIHpHz6Mcbv9t3KKDmIGTxW wHzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AAbjh4o1; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 131-20020a630189000000b005139e0d0dfesi13053887pgb.780.2023.04.05.09.38.56; Wed, 05 Apr 2023 09:39:09 -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=@kernel.org header.s=k20201202 header.b=AAbjh4o1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232921AbjDEQWk (ORCPT + 99 others); Wed, 5 Apr 2023 12:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233075AbjDEQWd (ORCPT ); Wed, 5 Apr 2023 12:22:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E75E56EAC for ; Wed, 5 Apr 2023 09:22:27 -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 4FA8663F85 for ; Wed, 5 Apr 2023 16:22:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1A5BC433D2; Wed, 5 Apr 2023 16:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680711746; bh=IKKd5/z6diLNwuttq1cK4BoG4eEmFEMFdox28Mo3uos=; h=From:To:Cc:Subject:Date:From; b=AAbjh4o1z/necfAjZKY1Sln6VweDJ7xXWEsUoZ2KWAdtadfcbfHDyuFfdCPjQ0TV0 /QnxXK3/AzDHI4I909K4A7pA9y8k6e9uijWFJxSGnvy6oq8YVqfG7syd7wn+VyZVa9 JOuBZI80K3uFps/zD19EUN2gzKbqwo0KcDTMD3oJkOfs6Vq4dcmLglKBPdHz1C9NH4 HcIJt+yzuXVDGUyrfy2izT+eWHTvDHXYWSOvcMgDDcdXhbwN6OoHixI8ZgqrbIM38v DnS4ll5JbOu2168GJa0B8boo+ZnUr/W13wj6VEbcyKRJ7YquVi5T315DYgrSBloAlc +QNzVWlmiwdjQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Daeho Jeong Subject: [PATCH] f2fs: fix to check return value of inc_valid_block_count() Date: Wed, 5 Apr 2023 22:45:36 +0800 Message-Id: <20230405144536.930370-1-chao@kernel.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762355051945788565?= X-GMAIL-MSGID: =?utf-8?q?1762355051945788565?= In __replace_atomic_write_block(), we missed to check return value of inc_valid_block_count(), for extreme testcase that f2fs image is run out of space, it may cause inconsistent status in between SIT table and total valid block count. Cc: Daeho Jeong Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index fc0734e4fb92..17203e8b865a 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -246,10 +246,16 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index, } else { blkcnt_t count = 1; + err = inc_valid_block_count(sbi, inode, &count); + if (err) { + f2fs_put_dnode(&dn); + return err; + } + *old_addr = dn.data_blkaddr; f2fs_truncate_data_blocks_range(&dn, 1); dec_valid_block_count(sbi, F2FS_I(inode)->cow_inode, count); - inc_valid_block_count(sbi, inode, &count); + f2fs_replace_block(sbi, &dn, dn.data_blkaddr, new_addr, ni.version, true, false); }