Skip to contentSkip to conversation

fsck.f2fs: fix sanity check logic for cp_payload

PATCH In review Juhyung Park 3 participants 5 messages Apr 4, 2023 – Apr 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 fsck/mount.c      | 2 +-
 include/f2fs_fs.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 2b26701..df0314d 100644
@@ -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;
include/f2fs_fs.h +4 -0
index 333ae07..f890634 100644
@@ -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.
Signature · 8 lines
2.40.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

Hi Jaegeuk,

Thanks for the timely merge.

Can we have a new f2fs-tools tag with this commit in place? Alex (the original bug reporter) would like to see this incorporated in the next version of Ubuntu (and Debian), and having a new tag is much easier to convince them to pack a new tag than having one patch backported.

In a practical scenario, a 2TB partition formatted with mkfs.f2fs -i simply doesn't boot under Ubuntu as fsck.f2fs inside the initramfs returns an error.

This patch fixes that and therefore allows the users to boot normally without manually excluding the f2fs partition to be checked during boot.

Thanks. Regards

Quoted 46 lines · Juhyung Park

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.

---
 fsck/mount.c      | 2 +-
 include/f2fs_fs.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 2b26701..df0314d 100644
@@ -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;
include/f2fs_fs.h +4 -1
index 333ae07..f890634 100644
@@ -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.
--
Quoted 2 lines

2.40.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 10 lines · Juhyung Park

Hi Jaegeuk,

Thanks for the timely merge.

Can we have a new f2fs-tools tag with this commit in place? Alex (the original bug reporter) would like to see this incorporated in the next version of Ubuntu (and Debian), and having a new tag is much easier to convince them to pack a new tag than having one patch backported.

Quoted 7 lines

In a practical scenario, a 2TB partition formatted with mkfs.f2fs -i simply doesn't boot under Ubuntu as fsck.f2fs inside the initramfs returns an error.

This patch fixes that and therefore allows the users to boot normally without manually excluding the f2fs partition to be checked during boot.

Thank you for heads up. I released v1.16.0. Please check. :)

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/tag/?h=v1.16.0

Quoted 47 lines

Thanks. Regards

Quoted 43 lines · Juhyung Park

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.

---
 fsck/mount.c      | 2 +-
 include/f2fs_fs.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 2b26701..df0314d 100644
@@ -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;
include/f2fs_fs.h +4 -0
index 333ae07..f890634 100644
@@ -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)
 
Quoted 5 lines
Quoted 5 lines
include/f2fs_fs.h +0 -1
 /*
  * Note that f2fs_sit_entry->vblocks has the following bit-field information.
--

2.40.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
In reply to Juhyung Park
Quoted 34 lines · Juhyung Park

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.

---
  fsck/mount.c      | 2 +-
  include/f2fs_fs.h | 4 ++++
  2 files changed, 5 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 2b26701..df0314d 100644
@@ -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;
include/f2fs_fs.h +0 -0
index 333ae07..f890634 100644

include/f2fs_fs.h static_assert(sizeof(struct f2fs_nat_block) == 4095, ""); · line 1172

Quoted 5 lines
include/f2fs_fs.h +2 -0
@@ -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 * \

DEFAULT_NAT_ENTRY_RATIO is 20 now, if we change it to 100 later, old fsck will still report error on a new image?

Should we remove "DEFAULT_NAT_ENTRY_RATIO / 100"?

Thanks,

include/f2fs_fs.h static_assert(sizeof(struct f2fs_nat_block) == 4095, ""); · line 1177

Quoted 5 lines
include/f2fs_fs.h +2 -0
+						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.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 45 lines · Chao Yu
Quoted 34 lines · Juhyung Park

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.

---
  fsck/mount.c      | 2 +-
  include/f2fs_fs.h | 4 ++++
  2 files changed, 5 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 2b26701..df0314d 100644
@@ -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;
include/f2fs_fs.h +0 -0
index 333ae07..f890634 100644

include/f2fs_fs.h static_assert(sizeof(struct f2fs_nat_block) == 4095, ""); · line 1172

Quoted 5 lines
include/f2fs_fs.h +2 -0
@@ -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 * \

DEFAULT_NAT_ENTRY_RATIO is 20 now, if we change it to 100 later, old fsck will still report error on a new image?

Quoted 2 lines

Should we remove "DEFAULT_NAT_ENTRY_RATIO / 100"?

That's a valid concern, if we plan to increase it in the future. I wasn't sure how strict the overflow check must be done.

Feel free to send a patch to increase this.

I suppose your concern doesn't really have an immediate practical impact as this is set from mkfs and isn't user configurable.

Thanks,

Quoted 7 lines

Thanks,

Quoted 5 lines
include/f2fs_fs.h +2 -0
+                                             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.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel