]>
Commit | Line | Data |
---|---|---|
c2a518a0 GKH |
1 | From foo@baz Fri Jan 18 09:16:11 CET 2019 |
2 | From: Martin Blumenstingl <martin.blumenstingl@googlemail.com> | |
3 | Date: Sat, 22 Dec 2018 11:22:26 +0100 | |
4 | Subject: f2fs: fix validation of the block count in sanity_check_raw_super | |
5 | ||
6 | From: Martin Blumenstingl <martin.blumenstingl@googlemail.com> | |
7 | ||
8 | commit 88960068f25fcc3759455d85460234dcc9d43fef upstream. | |
9 | ||
10 | Treat "block_count" from struct f2fs_super_block as 64-bit little endian | |
11 | value in sanity_check_raw_super() because struct f2fs_super_block | |
12 | declares "block_count" as "__le64". | |
13 | ||
14 | This fixes a bug where the superblock validation fails on big endian | |
15 | devices with the following error: | |
16 | F2FS-fs (sda1): Wrong segment_count / block_count (61439 > 0) | |
17 | F2FS-fs (sda1): Can't find valid F2FS filesystem in 1th superblock | |
18 | F2FS-fs (sda1): Wrong segment_count / block_count (61439 > 0) | |
19 | F2FS-fs (sda1): Can't find valid F2FS filesystem in 2th superblock | |
20 | As result of this the partition cannot be mounted. | |
21 | ||
22 | With this patch applied the superblock validation works fine and the | |
23 | partition can be mounted again: | |
24 | F2FS-fs (sda1): Mounted with checkpoint version = 7c84 | |
25 | ||
26 | My little endian x86-64 hardware was able to mount the partition without | |
27 | this fix. | |
28 | To confirm that mounting f2fs filesystems works on big endian machines | |
29 | again I tested this on a 32-bit MIPS big endian (lantiq) device. | |
30 | ||
31 | Fixes: 0cfe75c5b01199 ("f2fs: enhance sanity_check_raw_super() to avoid potential overflows") | |
32 | Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> | |
33 | Reviewed-by: Chao Yu <yuchao0@huawei.com> | |
34 | Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> | |
35 | Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> | |
36 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
37 | --- | |
38 | fs/f2fs/super.c | 6 +++--- | |
39 | 1 file changed, 3 insertions(+), 3 deletions(-) | |
40 | ||
41 | --- a/fs/f2fs/super.c | |
42 | +++ b/fs/f2fs/super.c | |
43 | @@ -1081,10 +1081,10 @@ static int sanity_check_raw_super(struct | |
44 | return 1; | |
45 | } | |
46 | ||
47 | - if (segment_count > (le32_to_cpu(raw_super->block_count) >> 9)) { | |
48 | + if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) { | |
49 | f2fs_msg(sb, KERN_INFO, | |
50 | - "Wrong segment_count / block_count (%u > %u)", | |
51 | - segment_count, le32_to_cpu(raw_super->block_count)); | |
52 | + "Wrong segment_count / block_count (%u > %llu)", | |
53 | + segment_count, le64_to_cpu(raw_super->block_count)); | |
54 | return 1; | |
55 | } | |
56 |