Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28149imm; Fri, 21 Sep 2018 17:23:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV61b5joXbiJFFW5OT/YjofqRykW26QKihUEYkOlvRdLPPUT/w7L7uFWvgizTyWQ5A3lSUIg3 X-Received: by 2002:a17:902:7c0a:: with SMTP id x10-v6mr105400pll.77.1537575796467; Fri, 21 Sep 2018 17:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575796; cv=none; d=google.com; s=arc-20160816; b=cfeb9St18xfPD1jOqOZ6qCe8jrf65oU6iC5Z67bi1zQqJSO/9NuNtaZsKrLpgzHIam 6Ii2sRM/xsL8RICDVvfsrFoK9TJcueWgBHjCpUcvwMiQFxqfRQmFja/sf+AEqPW1c1wJ aRkdj1jKisxFHsrcSJPFYK0AqZRiVkO4Zl0OK1d/+NQHxSOLw3acGmyQtT7YPelFX+kr 1NZAxWG4rG5Qns/3x05hY1E6PrK5xQnoGTEURhFkd5NsUSSydmJZ8Si/K9BzT2OkrVfZ bFSiIYNAYmgyiNmWt1uU7o00GKoZaW1uD2cxVr98cS6+Cz8kYiWP0joWmjqjhq9jMG08 qxlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=AD3XD/L/Q0Eug3z3iNJYLL3bVXXgPcpOF95FQlqg2BA=; b=LmwmYRP25oSnfyL6DPRYJPmexAHNXd8Lz7UZH/UshKdT0z/QR6BVoJg3G7vLpitbnK fE4QM8PhZ/snNUk1nbSqBxEbWGEwMVuD2EJUyPgv/Eio2jwmfikBQco4zBDeVD0R71Ib HCjA/WRgq1OI1tKvVk/sldd/9RWsrWzR8G3GXGdNE9VZF229oBitBRd+gxwCa9zxLTVy FghxsFCw5O48+3HAIJ/obd/kUAA3WHhMsgJ14JvgIONtgT+hxLVDZ0xfFo+lMrJFtXMm qXnrLiblUsyYle0D+k314EBUqKSySoXMUTNPTDrKoIXsKiDaTHLM9o/MydPdu0k7tapF BIbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o20-v6si29387829pgd.58.2018.09.21.17.23.00; Fri, 21 Sep 2018 17:23:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392201AbeIVGNK (ORCPT + 99 others); Sat, 22 Sep 2018 02:13:10 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44247 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392010AbeIVGKs (ORCPT ); Sat, 22 Sep 2018 02:10:48 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vdy-0008Bb-6e; Sat, 22 Sep 2018 01:19:30 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdo-0000rw-1X; Sat, 22 Sep 2018 01:19:20 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Harsh Shandilya" , "Theodore Ts'o" , "Greg Kroah-Hartman" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 28/63] ext4: don't allow r/w mounts if metadata blocks overlap the superblock In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.58-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Harsh Shandilya Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- fs/ext4/super.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2115,6 +2115,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: " @@ -2127,6 +2129,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: " @@ -2139,6 +2143,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) {