kernel: fix f2fs on big endian machines
[openwrt/openwrt.git] / target / linux / generic / pending-4.19 / 510-f2fs-fix-sanity_check_raw_super-on-big-endian-machines.patch
1 From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
2 Subject: [PATCH v2 1/1] f2fs: fix validation of the block count in
3 sanity_check_raw_super
4 Date: Sat, 22 Dec 2018 11:22:26 +0100
5 Message-Id: <20181222102226.10050-2-martin.blumenstingl@googlemail.com>
6
7 Treat "block_count" from struct f2fs_super_block as 64-bit little endian
8 value in sanity_check_raw_super() because struct f2fs_super_block
9 declares "block_count" as "__le64".
10
11 This fixes a bug where the superblock validation fails on big endian
12 devices with the following error:
13 F2FS-fs (sda1): Wrong segment_count / block_count (61439 > 0)
14 F2FS-fs (sda1): Can't find valid F2FS filesystem in 1th superblock
15 F2FS-fs (sda1): Wrong segment_count / block_count (61439 > 0)
16 F2FS-fs (sda1): Can't find valid F2FS filesystem in 2th superblock
17 As result of this the partition cannot be mounted.
18
19 With this patch applied the superblock validation works fine and the
20 partition can be mounted again:
21 F2FS-fs (sda1): Mounted with checkpoint version = 7c84
22
23 My little endian x86-64 hardware was able to mount the partition without
24 this fix.
25 To confirm that mounting f2fs filesystems works on big endian machines
26 again I tested this on a 32-bit MIPS big endian (lantiq) device.
27
28 Fixes: 0cfe75c5b01199 ("f2fs: enhance sanity_check_raw_super() to avoid potential overflows")
29 Cc: stable@vger.kernel.org
30 Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
31 Reviewed-by: Chao Yu <yuchao0@huawei.com>
32 ---
33
34 --- a/fs/f2fs/super.c
35 +++ b/fs/f2fs/super.c
36 @@ -2267,10 +2267,10 @@ static int sanity_check_raw_super(struct
37 return 1;
38 }
39
40 - if (segment_count > (le32_to_cpu(raw_super->block_count) >> 9)) {
41 + if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) {
42 f2fs_msg(sb, KERN_INFO,
43 - "Wrong segment_count / block_count (%u > %u)",
44 - segment_count, le32_to_cpu(raw_super->block_count));
45 + "Wrong segment_count / block_count (%u > %llu)",
46 + segment_count, le64_to_cpu(raw_super->block_count));
47 return 1;
48 }
49