Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1777319imm; Thu, 27 Sep 2018 02:17:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV61BHa8C6zy3ohoUUcp0Y3p62oizVORJaStNeD2yhn1ct/AoQoG1EgRPPskx9ZN5Prk0MsIc X-Received: by 2002:a63:6b05:: with SMTP id g5-v6mr9239326pgc.344.1538039857027; Thu, 27 Sep 2018 02:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039857; cv=none; d=google.com; s=arc-20160816; b=Fd4XY38cddutB/XfxOU/50y7NtRdannUmmr4fdFOByGATy2gLPIuRq7nUIwRpMpWqU Fv7zTM3v+0s5/U1XbqcqN8K9ff7U8ap/Kd4nDl9DRINjPBivSB2eQkPWNYTcge7PeoZw CvX2i5/DxMzIcuzgyrgIrtnsFiQJ55Kbn4VHs7SJeYZPiqXaEp8xsP+fYYsdtOsO4vNf 4dtMd7QAd0tWNEClcVlHUZHAs9gqclC/QkWsEl2N6GzW7ac/s8iPr0YbYHhRu8HnylWz 4KJgnxx1Eyn0WvNbvfnP46XsrcjhjoLjXe+4EbHrEl88sleJws6ayejQklRmi3Ffz9/T YLNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=60QOtKonJApkb47Ofgu46xrRo9IiXbQ6HLsH8IZPxUw=; b=vdiN8nRteD+zCIliTaCAJU5Jw4jmHHtyZF3rukH7P4BqgeTufyhfW3nyQb5jOP1s13 KMlz563PsbhBCnL5EAJWIEXdlu5udHLvPVlbwUSiUor561rQowpwCQyGz7utFLHcXblt gMNjIvyTf7sHm8aHCfVFJsuikV3az8zax4Exi6muuKMGkUvZ4JKlmo222Aa+Zt6LUkpe N4I0dIrh73deNs38fLK/i2RULDcqr/gnvWitgDMjWU7JtgJF386zgjuICstBIIYxaAfJ I+1I2WLM5uGJO+zns6jQIYk3jZYebciGkhJ2VQXL2OuOOpaQBp+vfJV2mlFyTQUjxx0L NY0Q== 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 j12-v6si1443916plk.196.2018.09.27.02.17.22; Thu, 27 Sep 2018 02:17:36 -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 S1728511AbeI0PcD (ORCPT + 99 others); Thu, 27 Sep 2018 11:32:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55542 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727108AbeI0PcD (ORCPT ); Thu, 27 Sep 2018 11:32:03 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DDA131117; Thu, 27 Sep 2018 09:14:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Torsten Hilbrich , Theodore Tso Subject: [PATCH 4.18 80/88] ext4: fix online resizes handling of a too-small final block group Date: Thu, 27 Sep 2018 11:04:01 +0200 Message-Id: <20180927090310.334721472@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090300.631426620@linuxfoundation.org> References: <20180927090300.631426620@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit f0a459dec5495a3580f8d784555e6f8f3bf7f263 upstream. Avoid growing the file system to an extent so that the last block group is too small to hold all of the metadata that must be stored in the block group. This problem can be triggered with the following reproducer: umount /mnt mke2fs -F -m0 -b 4096 -t ext4 -O resize_inode,^has_journal \ -E resize=1073741824 /tmp/foo.img 128M mount /tmp/foo.img /mnt truncate --size 1708M /tmp/foo.img resize2fs /dev/loop0 295400 umount /mnt e2fsck -fy /tmp/foo.img Reported-by: Torsten Hilbrich Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/resize.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1986,6 +1986,26 @@ retry: } } + /* + * Make sure the last group has enough space so that it's + * guaranteed to have enough space for all metadata blocks + * that it might need to hold. (We might not need to store + * the inode table blocks in the last block group, but there + * will be cases where this might be needed.) + */ + if ((ext4_group_first_block_no(sb, n_group) + + ext4_group_overhead_blocks(sb, n_group) + 2 + + sbi->s_itb_per_group + sbi->s_cluster_ratio) >= n_blocks_count) { + n_blocks_count = ext4_group_first_block_no(sb, n_group); + n_group--; + n_blocks_count_retry = 0; + if (resize_inode) { + iput(resize_inode); + resize_inode = NULL; + } + goto retry; + } + /* extend the last group */ if (n_group == o_group) add = n_blocks_count - o_blocks_count;