Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28388imm; Fri, 21 Sep 2018 17:23:39 -0700 (PDT) X-Google-Smtp-Source: ACcGV61909SOrSAvIG8W4VGEeKcOKnErlWYnJtOKDZNwaYTBSI6Zqg3R2jsq6DGncSj3Pu6yt5xM X-Received: by 2002:a17:902:e20b:: with SMTP id ce11-v6mr129921plb.136.1537575819669; Fri, 21 Sep 2018 17:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575819; cv=none; d=google.com; s=arc-20160816; b=a3t9MVtOS0ZKPLErv4RHkhp+YD0AcBDx3QPdM9ahguZD8kYYqlhmn+C/E0FzIDgAEv Br9/NpZtVw5XdAsOJ/SJjB0Dl7NHXE40jyn2+hiO404tuhmh2a7jdcRlDcCvt3f0S9ZF EjDRBPuWshtIc5mCRXk30ytyj0mzDAC6DgV0h79UK01DCK6OdS7ARErxYDpA557nesFg J+RLtZuLcvRGqPOW0UJHjUTACx+7nZcB2v7x3zUdbBdvdoQBp+KmqvpYx9ER20Ib0pgI 0B7VjJrQBLLBV784J1QFXLvMfD92qJwhBfQfu4ugZfgmTUZzUazozOWrOMFnGBQmBQeZ fvkA== 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=vgw1VC8h3cM5+ZQKPyQyG8FJCdXLVRDSgLmMIdlLrw8=; b=VZMPiyZhdnSXYykOFKGIOohGdObChRkkiJ+6EiZy0BMVfuFCIeQgA5HlIPwZXEMWSv PjggjR+LBJeiPT1GhJminJCzrH5wRpKikh7CdJbCPQ60KUcocrDwWsvyEiOQ3QRUgdwU hINo7IGie9gqvaZ8f3jOO8TVk2mWRULyrzeFqjCMf7qnJ26/xCFx4A2k9f0JzTDsjyqh KXoFNR8dVp8FoVXqR8Qvj6TfDb6QtjLS6ZbI413fZ82SO0HHWCBjTraEpAHXZml4S6Lv 1Juvj0lvBFaBmVTb32+8GZVTly0rcLOLfIeWCh9NzhaMUETaFDo8mrjidpsuHmETXZgE RN7g== 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 cd2-v6si31392057plb.47.2018.09.21.17.23.24; Fri, 21 Sep 2018 17:23:39 -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 S2392338AbeIVGNa (ORCPT + 99 others); Sat, 22 Sep 2018 02:13:30 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44234 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392004AbeIVGKs (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-0008Bd-6Y; Sat, 22 Sep 2018 01:19:30 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdo-0000s2-2n; 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, "Theodore Ts'o" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 29/63] ext4: make sure bitmaps and the inode table don't overlap with bg descriptors 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 77260807d1170a8cf35dbb06e07461a655f67eee upstream. It's really bad when the allocation bitmaps and the inode table overlap with the block group descriptors, since it causes random corruption of the bg descriptors. So we really want to head those off at the pass. https://bugzilla.kernel.org/show_bug.cgi?id=199865 Signed-off-by: Theodore Ts'o [bwh: Backported to 3.16: Open-code sb_rdonly()] Signed-off-by: Ben Hutchings --- fs/ext4/super.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2086,6 +2086,7 @@ static int ext4_check_descriptors(struct struct ext4_sb_info *sbi = EXT4_SB(sb); ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); ext4_fsblk_t last_block; + ext4_fsblk_t last_bg_block = sb_block + ext4_bg_num_gdb(sb, 0) + 1; ext4_fsblk_t block_bitmap; ext4_fsblk_t inode_bitmap; ext4_fsblk_t inode_table; @@ -2118,6 +2119,14 @@ static int ext4_check_descriptors(struct if (!(sb->s_flags & MS_RDONLY)) return 0; } + if (block_bitmap >= sb_block + 1 && + block_bitmap <= last_bg_block) { + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " + "Block bitmap for group %u overlaps " + "block group descriptors", 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: " "Block bitmap for group %u not in group " @@ -2132,6 +2141,14 @@ static int ext4_check_descriptors(struct if (!(sb->s_flags & MS_RDONLY)) return 0; } + if (inode_bitmap >= sb_block + 1 && + inode_bitmap <= last_bg_block) { + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " + "Inode bitmap for group %u overlaps " + "block group descriptors", 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: " "Inode bitmap for group %u not in group " @@ -2146,6 +2163,14 @@ static int ext4_check_descriptors(struct if (!(sb->s_flags & MS_RDONLY)) return 0; } + if (inode_table >= sb_block + 1 && + inode_table <= last_bg_block) { + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " + "Inode table for group %u overlaps " + "block group descriptors", i); + if (!(sb->s_flags & MS_RDONLY)) + return 0; + } if (inode_table < first_block || inode_table + sbi->s_itb_per_group - 1 > last_block) { ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "