From 7d1c34d341331cb17a8ebacfbf77c9327fa3252f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 22 Apr 2018 09:30:49 +0200 Subject: [PATCH] 4.9-stable patches added patches: ext4-don-t-allow-r-w-mounts-if-metadata-blocks-overlap-the-superblock.patch --- ...tadata-blocks-overlap-the-superblock.patch | 57 +++++++++++++++++++ queue-4.9/series | 1 + 2 files changed, 58 insertions(+) create mode 100644 queue-4.9/ext4-don-t-allow-r-w-mounts-if-metadata-blocks-overlap-the-superblock.patch diff --git a/queue-4.9/ext4-don-t-allow-r-w-mounts-if-metadata-blocks-overlap-the-superblock.patch b/queue-4.9/ext4-don-t-allow-r-w-mounts-if-metadata-blocks-overlap-the-superblock.patch new file mode 100644 index 00000000000..24df6dbbf24 --- /dev/null +++ b/queue-4.9/ext4-don-t-allow-r-w-mounts-if-metadata-blocks-overlap-the-superblock.patch @@ -0,0 +1,57 @@ +From 18db4b4e6fc31eda838dd1c1296d67dbcb3dc957 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Thu, 29 Mar 2018 22:10:35 -0400 +Subject: ext4: don't allow r/w mounts if metadata blocks overlap the superblock + +From: Theodore Ts'o + +commit 18db4b4e6fc31eda838dd1c1296d67dbcb3dc957 upstream. + +If some metadata block, such as an allocation bitmap, overlaps the +superblock, it's very likely that if the file system is mounted +read/write, the results will not be pretty. So disallow r/w mounts +for file systems corrupted in this particular way. + +Backport notes: +3.18.y is missing bc98a42c1f7d ("VFS: Convert sb->s_flags & MS_RDONLY to sb_rdonly(sb)") +and e462ec50cb5f ("VFS: Differentiate mount flags (MS_*) from internal superblock flags") +so we simply use the sb MS_RDONLY check from pre bc98a42c1f7d in place of the sb_rdonly +function used in the upstream variant of the patch. + +Signed-off-by: Theodore Ts'o +Cc: stable@vger.kernel.org +Signed-off-by: Harsh Shandilya +Signed-off-by: Greg Kroah-Hartman +--- + fs/ext4/super.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -2260,6 +2260,8 @@ static int ext4_check_descriptors(struct + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " + "Block bitmap for group %u overlaps " + "superblock", i); ++ if (!(sb->s_flags & MS_RDONLY)) ++ return 0; + } + if (block_bitmap < first_block || block_bitmap > last_block) { + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " +@@ -2272,6 +2274,8 @@ static int ext4_check_descriptors(struct + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " + "Inode bitmap for group %u overlaps " + "superblock", i); ++ if (!(sb->s_flags & MS_RDONLY)) ++ return 0; + } + if (inode_bitmap < first_block || inode_bitmap > last_block) { + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " +@@ -2284,6 +2288,8 @@ static int ext4_check_descriptors(struct + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " + "Inode table for group %u overlaps " + "superblock", i); ++ if (!(sb->s_flags & MS_RDONLY)) ++ return 0; + } + if (inode_table < first_block || + inode_table + sbi->s_itb_per_group - 1 > last_block) { diff --git a/queue-4.9/series b/queue-4.9/series index d9dc5b2fa53..766e5420c05 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -62,3 +62,4 @@ alsa-pcm-avoid-potential-races-between-oss-ioctls-and-read-write.patch alsa-pcm-return-ebusy-for-oss-ioctls-changing-busy-streams.patch alsa-pcm-fix-mutex-unbalance-in-oss-emulation-ioctls.patch alsa-pcm-fix-endless-loop-for-xrun-recovery-in-oss-emulation.patch +ext4-don-t-allow-r-w-mounts-if-metadata-blocks-overlap-the-superblock.patch -- 2.47.3