ANDROID: Fix mismerge of f2fs into android-4.14-q
authorAlessandro Astone <ales.astone@gmail.com>
Sun, 20 Sep 2020 00:07:36 +0000 (02:07 +0200)
committerAlessandro Astone <ales.astone@gmail.com>
Sun, 20 Sep 2020 00:36:44 +0000 (02:36 +0200)
Change I83ba9fcf313ad7b08ed6d8f79411c72f9471523c on AOSP
for kernel/common mismerged the patch
  `f2fs: use EINVAL for superblock with invalid magic`

An error in validating the superblock checksum would return 1
but later be checked with IS_ERR().

To fix, correctly return -EFSCORRUPTED if the validation fails.
Also move the check for header magic at the top, as it was intended.

Change-Id: I3c048b299f87f74021dfe7ac382902fbff785611
Signed-off-by: Alessandro Astone <ales.astone@gmail.com>
fs/f2fs/super.c

index b154322367390078c738907dd99ce0dcef26eef2..03ec11746febe720a363aceeaede88492cd80a23 100644 (file)
@@ -2430,6 +2430,13 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
        size_t crc_offset = 0;
        __u32 crc = 0;
 
+       if (le32_to_cpu(raw_super->magic) != F2FS_SUPER_MAGIC) {
+               f2fs_msg(sb, KERN_INFO,
+                       "Magic Mismatch, valid(0x%x) - read(0x%x)",
+                       F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
+               return -EINVAL;
+       }
+
        /* Check checksum_offset and crc in superblock */
        if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) {
                crc_offset = le32_to_cpu(raw_super->checksum_offset);
@@ -2438,23 +2445,16 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
                        f2fs_msg(sb, KERN_INFO,
                                "Invalid SB checksum offset: %zu",
                                crc_offset);
-                       return 1;
+                       return -EFSCORRUPTED;
                }
                crc = le32_to_cpu(raw_super->crc);
                if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
                        f2fs_msg(sb, KERN_INFO,
                                "Invalid SB checksum value: %u", crc);
-                       return 1;
+                       return -EFSCORRUPTED;
                }
        }
 
-       if (le32_to_cpu(raw_super->magic) != F2FS_SUPER_MAGIC) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Magic Mismatch, valid(0x%x) - read(0x%x)",
-                       F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
-               return -EINVAL;
-       }
-
        /* Currently, support only 4KB page cache size */
        if (F2FS_BLKSIZE != PAGE_SIZE) {
                f2fs_msg(sb, KERN_INFO,