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 DF467C25B06 for ; Sun, 14 Aug 2022 16:26:15 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1oNGRK-0000DH-EY; Sun, 14 Aug 2022 16:26:14 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oNGR5-0000Cn-BP for linux-f2fs-devel@lists.sourceforge.net; Sun, 14 Aug 2022 16:25:59 +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:References: In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=K4BdPQMp4w0scReBpHzrKu4tYzwg/6iJG/b+58rDoHE=; b=bUsQmBHmhRpx3BkQLwVM9pHCEL A7YxMYN+boXqMFGModDAiUdxlaxh6wnUNuBEjQ1hUpnMn/Beox73+fERWA1cD2tGfYsbjPJaFdR97 prxNBAu5DxM5LejlNdThfLhrQKAqezbwdVpYyS1Pmpw54axnvAJEMx1VebBL0G8tzTpc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=K4BdPQMp4w0scReBpHzrKu4tYzwg/6iJG/b+58rDoHE=; b=dx5LP5/mhlWRGP+W05IP0LxIU2 qsZk69dIGcfRp+dNebzjUkguT3nZUy8u8w3TLYpiFtSlfQY/q4kh7MB2OtQGNRyehYSyxJFeyZFzK pSA0MiyazpYvNPAOz7KF84leNVaMOPC1ukc9LCK6n5rwUJOt4MkFHNS3J+X0v4wXSoVo=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1oNGR4-0008Vx-NG for linux-f2fs-devel@lists.sourceforge.net; Sun, 14 Aug 2022 16:25:59 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 5ACED60FB1; Sun, 14 Aug 2022 16:25:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAE0DC43141; Sun, 14 Aug 2022 16:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660494352; bh=UXrvQ85jeUzk4EXykGsxWHwVxHqjVXFyQ60c+WCIULc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GHbBpT2MHsqCIMMyEYfh6JO/d4M9yjBsXIxMDAkQFDvN59yHOMkhhlldxBtIEd8Lh yB1aXzSi+FxXl7WwQjYNwKrFUbjqu6mvb49XjsxLbT2UclrCr68/7Z0he0vxtAXTXU 48dyAtmZxJNXNKQEwP65Qv5XkMo7uvNUKGuHq6CQbwzV5uqow60+dgP4QPFDLP5tUf MQFd9FP4jn2S2PDd5KrCm6UJc1eBoCOdNqIXa8/Bm5FblNpT20UbFmTk8Kz0rYJHUl /i59ySJ3JIoSzieL0emyIAExkpgb/5ZoYZC+eAb4CA+zh9oz8+9+cKn+fXDvxBM0/I DGR0gJxefYTbA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Sun, 14 Aug 2022 12:23:23 -0400 Message-Id: <20220814162332.2396012-34-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814162332.2396012-1-sashal@kernel.org> References: <20220814162332.2396012-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Headers-End: 1oNGR4-0008Vx-NG Subject: [f2fs-dev] [PATCH AUTOSEL 5.18 34/39] 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: Sasha Levin , Wenqing Liu , linux-f2fs-devel@lists.sourceforge.net, Jaegeuk Kim Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Chao Yu [ Upstream commit 09beadf289d6e300553e60d6e76f13c0427ecab3 ] 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 Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/segment.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index aa0162664a1e..15c72bfca692 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4486,6 +4486,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)) { @@ -4534,6 +4540,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.35.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA91AC32792 for ; Sun, 14 Aug 2022 16:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242531AbiHNQcg (ORCPT ); Sun, 14 Aug 2022 12:32:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242749AbiHNQbP (ORCPT ); Sun, 14 Aug 2022 12:31:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00DB13F79; Sun, 14 Aug 2022 09:25:55 -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 ams.source.kernel.org (Postfix) with ESMTPS id 1BF73B80B7F; Sun, 14 Aug 2022 16:25:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAE0DC43141; Sun, 14 Aug 2022 16:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660494352; bh=UXrvQ85jeUzk4EXykGsxWHwVxHqjVXFyQ60c+WCIULc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GHbBpT2MHsqCIMMyEYfh6JO/d4M9yjBsXIxMDAkQFDvN59yHOMkhhlldxBtIEd8Lh yB1aXzSi+FxXl7WwQjYNwKrFUbjqu6mvb49XjsxLbT2UclrCr68/7Z0he0vxtAXTXU 48dyAtmZxJNXNKQEwP65Qv5XkMo7uvNUKGuHq6CQbwzV5uqow60+dgP4QPFDLP5tUf MQFd9FP4jn2S2PDd5KrCm6UJc1eBoCOdNqIXa8/Bm5FblNpT20UbFmTk8Kz0rYJHUl /i59ySJ3JIoSzieL0emyIAExkpgb/5ZoYZC+eAb4CA+zh9oz8+9+cKn+fXDvxBM0/I DGR0gJxefYTbA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Yu , Wenqing Liu , Jaegeuk Kim , Sasha Levin , chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.18 34/39] f2fs: fix to do sanity check on segment type in build_sit_entries() Date: Sun, 14 Aug 2022 12:23:23 -0400 Message-Id: <20220814162332.2396012-34-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220814162332.2396012-1-sashal@kernel.org> References: <20220814162332.2396012-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Chao Yu [ Upstream commit 09beadf289d6e300553e60d6e76f13c0427ecab3 ] 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 Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/segment.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index aa0162664a1e..15c72bfca692 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4486,6 +4486,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)) { @@ -4534,6 +4540,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.35.1