erofs-utils: fix superblock checksum for sub-page block filesystems
PATCH 1/1 erofs-utils: fix superblock checksum for sub-page block filesystems
- sb_csum isn't generated properly for 512- or 1024-byte filesystem block sizes.
- Add --no-sbcrc option to fsck.erofs to bypass the sb_csum check.
Signed-off-by Gao Xiang <[email protected]>
--- fsck/main.c | 40 ++++++++----------------------- include/erofs/internal.h | 1 + lib/super.c | 51 ++++++++++++++++++++++++++++++---------- man/fsck.erofs.1 | 3 +++ 4 files changed, 52 insertions(+), 43 deletions(-)
fsck/main.c +10 -30
@@ -41,6 +41,7 @@ struct erofsfsck_cfg {bool preserve_owner;bool preserve_perms;bool dump_xattrs; +bool nosbcrc; };static struct erofsfsck_cfg fsckcfg;
@@ -60,6 +61,7 @@ static struct option long_options[] = { {"offset", required_argument, 0, 12}, {"xattrs", no_argument, 0, 13}, {"no-xattrs", no_argument, 0, 14}, + {"no-sbcrc", no_argument, 0, 512}, {0, 0, 0, 0}, };
@@ -110,6 +112,7 @@ static void usage(int argc, char **argv)" --extract[=X] check if all files are well encoded, optionally\n" " extract to X\n" " --offset=# skip # bytes at the beginning of IMAGE\n" +" --no-sbcrc bypass the superblock checksum verification\n" " --[no-]xattrs whether to dump extended attributes (default off)\n" "\n" " -a, -A, -y no-op, for compatibility with fsck of other filesystems\n"
@@ -244,6 +247,9 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)case 14 : fsckcfg.dump_xattrs = false;break ; +case 512 : + fsckcfg.nosbcrc = true; +break ;default :return -EINVAL ; }
@@ -322,35 +328,6 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path) } } -static int erofs_check_sb_chksum (void ) -{ -#ifndef FUZZING -u8 buf[EROFS_MAX_BLOCK_SIZE ]; -u32 crc; -struct erofs_super_block *sb; -int ret; - - ret =erofs_blk_read (&g_sbi,0 , buf,0 ,1 ); -if (ret) { -erofs_err ("failed to read superblock to check checksum: %d" , - ret); -return -1 ; - } - - sb = (struct erofs_super_block *)(buf +EROFS_SUPER_OFFSET ); - sb->checksum =0 ; - - crc =erofs_crc32c (~0 , (u8 *)sb,erofs_blksiz (&g_sbi) -EROFS_SUPER_OFFSET ); -if (crc != g_sbi.checksum) { -erofs_err ("superblock chksum doesn't match: saved(%08xh) calculated(%08xh)" , - g_sbi.checksum, crc); - fsckcfg.corrupted = true; -return -1 ; - } -#endif -return 0 ; -} -static int erofs_verify_xattr (struct erofs_inode *inode) {struct erofs_sb_info *sbi = inode->sbi;
@@ -1066,6 +1043,7 @@ int main(int argc, char *argv[])#ifdef FUZZING cfg.c_dbg_lvl =-1 ; + fsckcfg.nosbcrc = true;#endif err =erofs_dev_open (&g_sbi, cfg.c_img_path,O_RDONLY );
@@ -1080,7 +1058,9 @@ int main(int argc, char *argv[]) goto exit_dev_close; } -if (erofs_sb_has_sb_chksum (&g_sbi) &&erofs_check_sb_chksum ()) { +if (!fsckcfg.nosbcrc &&erofs_sb_has_sb_chksum (&g_sbi) && +erofs_superblock_csum_verify (&g_sbi)) { + fsckcfg.corrupted = true;erofs_err ("failed to verify superblock checksum" ); goto exit_put_super; }
include/erofs/internal.h +1 -0
@@ -419,6 +419,7 @@ struct erofs_buffer_head *erofs_reserve_sb(struct erofs_bufmgr *bmgr);int erofs_mkfs_init_devices (struct erofs_sb_info *sbi,unsigned int devices);int erofs_write_device_table (struct erofs_sb_info *sbi);int erofs_enable_sb_chksum (struct erofs_sb_info *sbi,u32 *crc); +int erofs_superblock_csum_verify (struct erofs_sb_info *sbi);/* namei.c */ int erofs_read_inode_from_disk (struct erofs_inode *vi);
lib/super.c +38 -13
82 lines not on this page · raw message
man/fsck.erofs.1 +3 -0
@@ -34,6 +34,9 @@ take a long time depending on the image size. Optionally extract contents of the \fIIMAGE\fR to \fIdirectory\fR. .TP +.B "--no-sbcrc" +Bypass the on-disk superblock checksum verification. +.TP .BI "--[no-]xattrs" Whether to dump extended attributes during extraction (default off). .TP
Signature · 1 line
2.43.5