Update fixes for making ext4 more robust against malicious images
[ext4-patch-queue.git] / dont-allow-rw-mounts-of-metadata-blocks-over-lap-sb
blobd4232a0e47758ddd19a9a1981174ec23fc7aecce
1 ext4: don't allow r/w mounts if metadata blocks overlap the superblock
3 If some metadata block, such as an allocation bitmap, overlaps the
4 superblock, it's very likely that if the file system is mounted
5 read/write, the results will not be pretty.  So disallow r/w mounts
6 for file systems corrupted in this particular way.
8 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 Cc: stable@vger.kernel.org
10 ---
11  fs/ext4/super.c | 6 ++++++
12  1 file changed, 6 insertions(+)
14 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
15 index 7cd022c344d1..edcfe6956eba 100644
16 --- a/fs/ext4/super.c
17 +++ b/fs/ext4/super.c
18 @@ -2335,6 +2335,8 @@ static int ext4_check_descriptors(struct super_block *sb,
19                         ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
20                                  "Block bitmap for group %u overlaps "
21                                  "superblock", i);
22 +                       if (!sb_rdonly(sb))
23 +                               return 0;
24                 }
25                 if (block_bitmap < first_block || block_bitmap > last_block) {
26                         ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
27 @@ -2347,6 +2349,8 @@ static int ext4_check_descriptors(struct super_block *sb,
28                         ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
29                                  "Inode bitmap for group %u overlaps "
30                                  "superblock", i);
31 +                       if (!sb_rdonly(sb))
32 +                               return 0;
33                 }
34                 if (inode_bitmap < first_block || inode_bitmap > last_block) {
35                         ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
36 @@ -2359,6 +2363,8 @@ static int ext4_check_descriptors(struct super_block *sb,
37                         ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
38                                  "Inode table for group %u overlaps "
39                                  "superblock", i);
40 +                       if (!sb_rdonly(sb))
41 +                               return 0;
42                 }
43                 if (inode_table < first_block ||
44                     inode_table + sbi->s_itb_per_group - 1 > last_block) {