aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuhyung Park <qkrwngud825@gmail.com>2023-04-04 14:54:46 +0900
committerJaegeuk Kim <jaegeuk@kernel.org>2023-04-07 13:31:18 -0700
commit542cc5741f778ae16b466b9b04d31e69079a3adf (patch)
treee1f5cb09becea4fa60fe827750a94d71841ae8ec
parenta7df89e5c52a3629176aa8bd2b81c9746084538d (diff)
downloadf2fs-tools-542cc5741f778ae16b466b9b04d31e69079a3adf.tar.gz
fsck.f2fs: fix sanity check logic for cp_payload
cp_payload is set differently [1] when extended node bitmap feature is enabled. Commit b79c3ba4ea9d broke fsck on f2fs file systems created on 2+ TB device with extended node bitmap feature enabled. As the sanity check is for checking overflows, fix this to assume the max possible cp_payload size under the extended node bitmap. Link: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/tree/mkfs/f2fs_format.c?h=v1.15.0#n372 [1] Fixes: b79c3ba4ea9d ("fsck.f2fs: sanity check cp_payload before reading checkpoint") Reported-by: Alexander Koskovich <akoskovich@pm.me> Signed-off-by: Juhyung Park <qkrwngud825@gmail.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fsck/mount.c2
-rw-r--r--include/f2fs_fs.h4
2 files changed, 5 insertions, 1 deletions
diff --git a/fsck/mount.c b/fsck/mount.c
index 2b26701..df0314d 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1208,7 +1208,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
int ret;
cp_payload = get_sb(cp_payload);
- if (cp_payload > F2FS_BLK_ALIGN(MAX_SIT_BITMAP_SIZE))
+ if (cp_payload > F2FS_BLK_ALIGN(MAX_CP_PAYLOAD))
return -EINVAL;
cp_blks = 1 + cp_payload;
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 333ae07..f890634 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1168,6 +1168,10 @@ static_assert(sizeof(struct f2fs_nat_block) == 4095, "");
#define MAX_SIT_BITMAP_SIZE (SEG_ALIGN(SIZE_ALIGN(F2FS_MAX_SEGMENT, \
SIT_ENTRY_PER_BLOCK)) * \
c.blks_per_seg / 8)
+#define MAX_CP_PAYLOAD (SEG_ALIGN(SIZE_ALIGN(UINT32_MAX, NAT_ENTRY_PER_BLOCK)) * \
+ DEFAULT_NAT_ENTRY_RATIO / 100 * \
+ c.blks_per_seg / 8 + \
+ MAX_SIT_BITMAP_SIZE - MAX_BITMAP_SIZE_IN_CKPT)
/*
* Note that f2fs_sit_entry->vblocks has the following bit-field information.