Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2009558imm; Tue, 10 Jul 2018 11:31:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcDnE5upyCnLUHfEejuvJUzvvvzmI4AlPUWvyr3KTStjfJJhCDvYiLEZsMany8BDX3ilk9Q X-Received: by 2002:a63:c44a:: with SMTP id m10-v6mr23874890pgg.416.1531247500712; Tue, 10 Jul 2018 11:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247500; cv=none; d=google.com; s=arc-20160816; b=F37I1p0YmE2HQrEIDtJvxKR/mRomXSFVEAmvj4Gb7w68hU2xVpFgk77X5eVGP8pnNV aXtlM40uDDY99MOoXFS0lwHVsH4RoojoSzADXL37yDMXtzDwcIhFvlV6w4lupw+gdPSy VwVpFONaUOnwobfsxrkyO6/gsGlDtFQMUVoBYNLwvgC5KjcU+CvDuJX1nd1c5AY91num 3Yd/UT94xziQf6a6lB4rmiSLQm1xTh0bi/T7ITQDuDQ736nHYbR+7Qx2WAnWxNc1B0M8 XUNUdSmIoH4hYzsWwgOmcLXl3WOKjXs5XjNt2I/xrajXh/itHOSX0mzq/CmEFgH7JnKd G6mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ssv1C1D15siaEuoQeNbURCdigqOJwCm+7P5bmIcKEZ4=; b=GZp7Lh8h0iESLmmWcHjzlfMrzUgOudVcPLyd1dLfJwhAslGVKkM/Iwe14GkBrnIWjm K/ybTBjUtSBuYI6dz907VxZGvfSJ7oRJnjt7u+DREOJkFF9nBlMAUSdnPfxTKeWZvA4E 4+qy5GMBme2vfLMI1zrm8qmDamjaBoweD/pj722EJ5/CTUxIGfHGd84NiyIpppIJMgN4 k+VR8yyOakFrv5II92NY+XZxqSdp8XgPDtIKTUmcsbJEfzOl0rzHONKiZHTpAoaqQdbJ /EvUXBAAMKak0x483SJDx1rhMiNSZqJFiJikJKCt7A3Wm6rzbKzg2PtqkscOXakyKigF xxCQ== 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 p7-v6si16378576plk.293.2018.07.10.11.31.24; Tue, 10 Jul 2018 11:31:40 -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 S2388011AbeGJSaT (ORCPT + 99 others); Tue, 10 Jul 2018 14:30:19 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45534 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732565AbeGJSaT (ORCPT ); Tue, 10 Jul 2018 14:30:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 221A7EB4; Tue, 10 Jul 2018 18:30:06 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org Subject: [PATCH 4.9 27/52] ext4: make sure bitmaps and the inode table dont overlap with bg descriptors Date: Tue, 10 Jul 2018 20:24:55 +0200 Message-Id: <20180710182451.996275202@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable 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 Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2231,6 +2231,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; @@ -2263,6 +2264,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 " @@ -2277,6 +2286,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 " @@ -2291,6 +2308,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: "