From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D2BAC04A68 for ; Wed, 27 Jul 2022 14:51:48 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1oGiO0-0007Aw-6R; Wed, 27 Jul 2022 14:51:45 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oGiNz-0007Aq-9j for linux-f2fs-devel@lists.sourceforge.net; Wed, 27 Jul 2022 14:51:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Fjt7Zjdd6/s5SBHLc8pLMVyjgtTq3gOfKu556cLDv2w=; b=FfCK4bocyaka0fHab9TQxxcBYr IDAcoWQqybSAD+ZZLMTaZELvmxoMXo3NGiBnP81XZ7TAskGmH3KKnNvLtjAd4YHvsQsr077KIUjXe boDvUcRjkoyWF/hqsrBqEYrd4Ypio+4e1RG78U6Lr1w1vJk7vZ9Wsz9MwxbSswm8viWs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=Fjt7Zjdd6/s5SBHLc8pLMVyjgtTq3gOfKu556cLDv2w=; b=D mSVEP/CS9nTtigWNheKpXndTb0YJTgAPDKPEYKX+4rg+W1csvRpqJkL7xwLyPSeTQsyZ23tmlgDcx pD8kJLYy5+oQgwxgqpPq/yRzlSSFYkwzb0tXlIflodcxCTZyjCUJodWwW1J6dndx5ka/8RT39CIB3 A9K0J5v7Byrc9ohY=; Received: from ams.source.kernel.org ([145.40.68.75]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1oGiNv-0004uD-LH for linux-f2fs-devel@lists.sourceforge.net; Wed, 27 Jul 2022 14:51:43 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 51524B82199; Wed, 27 Jul 2022 14:51:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECB78C433D6; Wed, 27 Jul 2022 14:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658933485; bh=vqSpCepPlYeE/5Z30CAjJpT4GBqxXF90RajlOgrTJLI=; h=From:To:Cc:Subject:Date:From; b=rXH5gsO3xi1jppwO0JGkyyXJe6nNvBnMS+zs7n4XDocHmIURshNFiwP9Rvoei9tMX y35Wh76pqxyj1CSdrPxcO/UzyLcdSov0iEDMgd26FHs/IKa3ET579CqCBygxyq/igc HE4e0PVoxOaSB1IDj+DCQLLcTRzpVLcS3tmKIKOSjc9zkcz4XVpqIX2qY0y51xYLN2 edOg0uEjR4ZiYyS2guPTzZvAD+1yPJLZTT3NnUY23bLFekJgNxwu8yDDGKJhN4tlKv r+gcZwpkwc4Ps1FoLxitZ4DkiGcpOgXgovqbFroyD0YDNfwqszAls9Q2UDs3lXzEfh EFTkwm1DTH7aQ== From: Chao Yu To: jaegeuk@kernel.org Date: Wed, 27 Jul 2022 22:51:05 +0800 Message-Id: <20220727145105.3502-1-chao@kernel.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Headers-End: 1oGiNv-0004uD-LH Subject: [f2fs-dev] [PATCH] f2fs: fix to do sanity check on segment type in build_sit_entries() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wenqing Liu , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Chao Yu As Wenqing Liu reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216285 RIP: 0010:memcpy_erms+0x6/0x10 f2fs_update_meta_page+0x84/0x570 [f2fs] change_curseg.constprop.0+0x159/0xbd0 [f2fs] f2fs_do_replace_block+0x5c7/0x18a0 [f2fs] f2fs_replace_block+0xeb/0x180 [f2fs] recover_data+0x1abd/0x6f50 [f2fs] f2fs_recover_fsync_data+0x12ce/0x3250 [f2fs] f2fs_fill_super+0x4459/0x6190 [f2fs] mount_bdev+0x2cf/0x3b0 legacy_get_tree+0xed/0x1d0 vfs_get_tree+0x81/0x2b0 path_mount+0x47e/0x19d0 do_mount+0xce/0xf0 __x64_sys_mount+0x12c/0x1a0 do_syscall_64+0x38/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd The root cause is segment type is invalid, so in f2fs_do_replace_block(), f2fs accesses f2fs_sm_info::curseg_array with out-of-range segment type, result in accessing invalid curseg->sum_blk during memcpy in f2fs_update_meta_page(). Fix this by adding sanity check on segment type in build_sit_entries(). Reported-by: Wenqing Liu Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 51da73b27a45..7b1d2c29aba6 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4375,6 +4375,12 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) return err; seg_info_from_raw_sit(se, &sit); + if (se->type >= NR_PERSISTENT_LOG) { + f2fs_err(sbi, "Invalid segment type: %u, segno: %u", + se->type, start); + return -EFSCORRUPTED; + } + sit_valid_blocks[SE_PAGETYPE(se)] += se->valid_blocks; if (f2fs_block_unit_discard(sbi)) { @@ -4423,6 +4429,13 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) break; seg_info_from_raw_sit(se, &sit); + if (se->type >= NR_PERSISTENT_LOG) { + f2fs_err(sbi, "Invalid segment type: %u, segno: %u", + se->type, start); + err = -EFSCORRUPTED; + break; + } + sit_valid_blocks[SE_PAGETYPE(se)] += se->valid_blocks; if (f2fs_block_unit_discard(sbi)) { -- 2.36.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel