Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1784853imm; Thu, 27 Sep 2018 02:26:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV62DH9+Bsl6hINNpE9L+VL3T58fzRR6yzXexyomHoPAbr5ZmtF+cakpY5B7/VgWWkGvNteu2 X-Received: by 2002:a62:7d8d:: with SMTP id y135-v6mr10324630pfc.245.1538040360686; Thu, 27 Sep 2018 02:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538040360; cv=none; d=google.com; s=arc-20160816; b=pYg/AJpgT+mjCZ5xd6OX3a91f/xVqnoI7rxg+0pzSVharIvxBLS8uXDvFtYsfD4Qhu bq5NyNoic2MSPqrcG+6N+/Im/GNa62HhKTCAZdzFF2iA7+nvzdlyGS3mpZyPEuo+UQxZ IT/Br2O+Ww88bQmqgbBCk2HJDiU0pVbXny5llzOnZMed/XP1avW+0SWXuBEBOdzyLTXq rY9dycSObvX43NMV2SchwWVQez3sbxgn/TLEvh8W3RmJHIAf0uB3vnCgyEvWWCu/AklH cNGmhZpodnuNBoOjB34YUiqo2I+k42L3X1p24fzwkhnD8dIQ114RMCyQ//ZmzortUuzZ 5fUQ== 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=lWP0ytqigN/oX5132ruRg7ijJEtfNni4uAlVu5Z2xqI=; b=nnsco2BGoj3T3e4c2IMp0H1jWraq5GRWWb+bQJKbh6wiCHTxSTE2ORn9n3DADTiIRc iF3z/IscQa/URlOnlGXvC2NogamEQ3QnHzYVeZNh10Mn6o7CXugSBNYoKYd7l/RrrTyu ygww+MTcOQejsiNncFbz7xOe7hsmrsINox+nEKbi4/mwEr5fGGkVH/khH7+4LN6LaPyC lphHJeJmt5t1r1MbXjjCLMVEH0jhABHGU+fJKR1j9n8mqS9cUM5Ke8B1lHA+EJUrBFtN ntGQh7y7xMoEnExqEcIkVObhE7wxSyxNW1D2wS4eYfqW3KMK4jRcQJtfQSKtZqiZoYRP 0OeA== 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 n12-v6si1509932pgl.136.2018.09.27.02.25.45; Thu, 27 Sep 2018 02:26:00 -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 S1728492AbeI0Plb (ORCPT + 99 others); Thu, 27 Sep 2018 11:41:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56654 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727154AbeI0Pla (ORCPT ); Thu, 27 Sep 2018 11:41:30 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1B42B1113; Thu, 27 Sep 2018 09:24:09 +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.14 55/64] ext4: fix online resizes handling of a too-small final block group Date: Thu, 27 Sep 2018 11:04:12 +0200 Message-Id: <20180927090257.552072627@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090249.801943776@linuxfoundation.org> References: <20180927090249.801943776@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.14-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 @@ -1956,6 +1956,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;