Return-Path: Received: from mail-pg0-f65.google.com ([74.125.83.65]:40361 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbeDVEZA (ORCPT ); Sun, 22 Apr 2018 00:25:00 -0400 Received: by mail-pg0-f65.google.com with SMTP id e9so6056805pgr.7 for ; Sat, 21 Apr 2018 21:25:00 -0700 (PDT) From: Harsh Shandilya To: stable@vger.kernel.org, tytso@mit.edu Cc: Harsh Shandilya Subject: [PATCH v3 3.18.y 3/3] ext4: don't allow r/w mounts if metadata blocks overlap the superblock Date: Sun, 22 Apr 2018 09:54:07 +0530 Message-Id: <20180422042407.5820-4-harsh@prjkt.io> In-Reply-To: <20180422042407.5820-1-harsh@prjkt.io> References: <20180422042407.5820-1-harsh@prjkt.io> Sender: stable-owner@vger.kernel.org List-ID: 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 --- 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