From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Chao Yu <chao.yu@oppo.com>,
Wenqing Liu <wenqingliu0120@gmail.com>,
Jaegeuk Kim <jaegeuk@kernel.org>, Sasha Levin <sashal@kernel.org>,
chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH AUTOSEL 5.15 23/28] f2fs: fix to do sanity check on segment type in build_sit_entries()
Date: Sun, 14 Aug 2022 12:26:03 -0400 [thread overview]
Message-ID: <20220814162610.2397644-23-sashal@kernel.org> (raw)
In-Reply-To: <20220814162610.2397644-1-sashal@kernel.org>
From: Chao Yu <chao.yu@oppo.com>
[ Upstream commit 09beadf289d6e300553e60d6e76f13c0427ecab3 ]
As Wenqing Liu <wenqingliu0120@gmail.com> 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 <wenqingliu0120@gmail.com>
Signed-off-by: Chao Yu <chao.yu@oppo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/f2fs/segment.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 841a978da083..e98c90bd8ef6 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -4537,6 +4537,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)) {
@@ -4585,6 +4591,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
next prev parent reply other threads:[~2022-08-14 16:35 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-14 16:25 [PATCH AUTOSEL 5.15 01/28] lib/list_debug.c: Detect uninitialized lists Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 02/28] tty: serial: Fix refcount leak bug in ucc_uart.c Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 03/28] KVM: PPC: Book3S HV: Fix "rm_exit" entry in debugfs timings Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 04/28] vfio: Clear the caps->buf to NULL after free Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 05/28] mips: cavium-octeon: Fix missing of_node_put() in octeon2_usb_clocks_start Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 06/28] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 07/28] modules: Ensure natural alignment for .altinstructions and __bug_table sections Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 08/28] ASoC: rsnd: care default case on rsnd_ssiu_busif_err_irq_ctrl() Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 09/28] riscv: dts: sifive: Add fu540 topology information Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 10/28] riscv: dts: sifive: Add fu740 " Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 11/28] riscv: dts: canaan: Add k210 " Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 12/28] riscv: mmap with PROT_WRITE but no PROT_READ is invalid Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 13/28] RISC-V: Add fast call path of crash_kexec() Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 14/28] watchdog: export lockup_detector_reconfigure Sasha Levin
2022-08-23 9:34 ` Laurent Dufour
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 15/28] powerpc/32: Set an IBAT covering up to _einittext during init Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 16/28] powerpc/32: Don't always pass -mcpu=powerpc to the compiler Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 17/28] ovl: warn if trusted xattr creation fails Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 18/28] powerpc/ioda/iommu/debugfs: Generate unique debugfs entries Sasha Levin
2022-08-14 16:25 ` [PATCH AUTOSEL 5.15 19/28] ALSA: core: Add async signal helpers Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 20/28] ALSA: timer: Use deferred fasync helper Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 21/28] ALSA: control: " Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 22/28] f2fs: fix to avoid use f2fs_bug_on() in f2fs_new_node_page() Sasha Levin
2022-08-14 16:26 ` Sasha Levin [this message]
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 24/28] smb3: check xattr value length earlier Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 25/28] powerpc/64: Init jump labels before parse_early_param() Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 26/28] venus: pm_helpers: Fix warning in OPP during probe Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 27/28] video: fbdev: i740fb: Check the argument of i740_calc_vclk() Sasha Levin
2022-08-14 16:26 ` [PATCH AUTOSEL 5.15 28/28] MIPS: tlbex: Explicitly compare _PAGE_NO_EXEC against 0 Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220814162610.2397644-23-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=chao.yu@oppo.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=wenqingliu0120@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox