From: Theodore Ts'o Date: Mon, 18 May 2020 03:05:11 +0000 (-0400) Subject: libext2fs: retry reading superblock on open when checksum is bad X-Git-Tag: v1.45.7~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6338a8467564c3a0a12e9fcb08bdd748d736ac2f;p=thirdparty%2Fe2fsprogs.git libext2fs: retry reading superblock on open when checksum is bad When opening a file system which is mounted, it's possible that when ext2fs_open2() is racing with the kernel modifying the orphaned inode list, the superblock's checksum could be incorrect. So retry reading the superblock in the hopes that the problem will self-correct. Google-Bug-Id: 151453112 Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 51b54a449..ae54870e5 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -134,6 +134,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, int j; #endif char *time_env; + int csum_retries = 0; EXT2_CHECK_MAGIC(manager, EXT2_ET_MAGIC_IO_MANAGER); @@ -221,6 +222,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, if (retval) goto cleanup; } +retry: retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE, fs->super); if (retval) @@ -232,8 +234,11 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, retval = 0; if (!ext2fs_verify_csum_type(fs, fs->super)) retval = EXT2_ET_UNKNOWN_CSUM; - if (!ext2fs_superblock_csum_verify(fs, fs->super)) + if (!ext2fs_superblock_csum_verify(fs, fs->super)) { + if (csum_retries++ < 3) + goto retry; retval = EXT2_ET_SB_CSUM_INVALID; + } } #ifdef WORDS_BIGENDIAN