Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Harsh Shandilya <harsh@prjkt.io>
To: stable@vger.kernel.org
Cc: Theodore Ts'o <tytso@mit.edu>, Harsh Shandilya <harsh@prjkt.io>
Subject: [PATCH 3/3] ext4: don't allow r/w mounts if metadata blocks overlap the superblock
Date: Sat, 21 Apr 2018 17:59:27 +0530	[thread overview]
Message-ID: <20180421122927.19842-1-harsh@prjkt.io> (raw)
In-Reply-To: <20180420222612.18881-4-harsh@prjkt.io>

From: Theodore Ts'o <tytso@mit.edu>

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 <tytso@mit.edu>
Cc: stable@vger.kernel.org
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
---
 fs/ext4/super.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 26a0c5dd0c97..8e92cab056cb 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2112,6 +2112,8 @@ static int ext4_check_descriptors(struct super_block *sb,
 			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: "
@@ -2124,6 +2126,8 @@ static int ext4_check_descriptors(struct super_block *sb,
 			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: "
@@ -2136,6 +2140,8 @@ static int ext4_check_descriptors(struct super_block *sb,
 			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) {
-- 
2.15.0.2308.g658a28aa74af

  reply	other threads:[~2018-04-21 12:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-20 22:26 [PATCH 0/4] 4.17-rc1 stable tagged ext4 patches for 3.18.y Harsh Shandilya
2018-04-20 22:26 ` [PATCH 1/4] ext4: add validity checks for bitmap block numbers Harsh Shandilya
2018-04-21 12:28   ` [PATCH 1/3] " Harsh Shandilya
2018-04-20 22:26 ` [PATCH 2/4] ext4: fail ext4_iget for root directory if unallocated Harsh Shandilya
2018-04-21 12:28   ` [PATCH 2/3] " Harsh Shandilya
2018-04-20 22:26 ` [PATCH 3/4] ext4: don't allow r/w mounts if metadata blocks overlap the superblock Harsh Shandilya
2018-04-21 12:29   ` Harsh Shandilya [this message]
2018-04-21 20:07     ` [PATCH 3/3] " Theodore Y. Ts'o
2018-04-22  2:30       ` Harsh Shandilya
2018-04-22  4:01         ` Theodore Y. Ts'o
2018-04-22  4:04           ` Harsh Shandilya
2018-04-20 22:26 ` [PATCH 4/4] ext4: force revalidation of directory pointer after seekdir(2) Harsh Shandilya
2018-04-20 23:23 ` [PATCH 0/4] 4.17-rc1 stable tagged ext4 patches for 3.18.y Harsh Shandilya
2018-04-21 12:21 ` [PATCH 0/3] " Harsh Shandilya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180421122927.19842-1-harsh@prjkt.io \
    --to=harsh@prjkt.io \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox