Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2977800imu; Sun, 9 Dec 2018 14:08:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/VtSTqcpkN8wH/9XRSdF8+JXtp9mpfMeGLddXOaQaGw6QC3Y2jZYQ95qA8ujefKxmrKB1g6 X-Received: by 2002:a17:902:541:: with SMTP id 59mr10051951plf.88.1544393311048; Sun, 09 Dec 2018 14:08:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393311; cv=none; d=google.com; s=arc-20160816; b=Mo5IG1cKEsWAd5Oij6RTvWyvgS972oAOgIeqijuKp0Eo9tKv0jG5lpiHUQAX2m+Ttl NZGDsfwlaY3Ld5SBfAueLYnVOmLm7qTpCxrrtBcvqIUssSmyMd47iISf9j0WHEjVCe2N KAf63PNkLabRBh50oPBzUQGBYVOCfFC1NC6zC3mh6ZjAsSHp/qoaDDkvCvPEm1958U3k SBzAOrxHANecbePll34Y4RHqwIGx8vLU/1x0METQ9gaQzIYjGSsKn58sv/VCAK4z2WcC /QS5l9VpS+2vBfC1I+CwFFoxlgfcRsFELjfWC3q1mqd5UoYCoXtZ5FWj3fYPBeYyUs3Z Rspg== 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=UHs1K3SZ2YYcoz5+3ppLq/sdIcAQQ/WwcOQZBDWwnik=; b=lD3s426jiCAHOaZUufRhqXsAjuSQIM7jHKGESJknUh/alupyMsK9uAac5LQrq90wv2 Nl+5+YGQxiEKA9mOjMl5F8r3sQLLT3B/sM1C9iIBgcNm30k7XEgY6HYgjCmpXfoySw+4 y2lwFQqP1oxoj5IaRGAhq46B9+sdeSeI8PELaLW9emWCTn1Y37UEt2wVspAJA6q+vihN NxVkM3Stwsdp5rn/pAB//vtuEsdnPmzguCDB8HEJRl65P8uDXXKmEZmpSgHjD8k6knwo PIP0nYdHXCPDCVrAeI3XMERKzmY5lixbrHHBCtmxSNPKGJHzilK+ASxis0OIOwdk4hG3 RDwA== 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 h19si8034295pgb.231.2018.12.09.14.08.15; Sun, 09 Dec 2018 14:08:31 -0800 (PST) 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 S1727798AbeLIWGq (ORCPT + 99 others); Sun, 9 Dec 2018 17:06:46 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37110 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726791AbeLIWGm (ORCPT ); Sun, 9 Dec 2018 17:06:42 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW738-0002ie-DN; Sun, 09 Dec 2018 21:55:43 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72f-0003TJ-G7; Sun, 09 Dec 2018 21:55:13 +0000 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" , "Torsten Hilbrich" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 187/328] ext4: fix online resize's handling of a too-small final block group In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 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.62-rc1 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 Signed-off-by: Ben Hutchings --- fs/ext4/resize.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -1957,6 +1957,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;