Stable Archive on lore.kernel.org
 help / Atom feed
* [PATCH] ext4: Fix crash during online resizing
@ 2019-01-24 16:26 Jan Kara
  2019-02-11 18:43 ` Theodore Y. Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2019-01-24 16:26 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Jan Kara, stable

When computing maximum size of filesystem possible with given number of
group descriptor blocks, we forget to include s_first_data_block into
the number of blocks. Thus for filesystems with non-zero
s_first_data_block it can happen that computed maximum filesystem size
is actually lower than current filesystem size which confuses the code
and eventually leads to a BUG_ON in ext4_alloc_group_tables() hitting on
flex_gd->count == 0. The problem can be reproduced like:

truncate -s 100g /tmp/image
mkfs.ext4 -b 1024 -E resize=262144 /tmp/image 32768
mount -t ext4 -o loop /tmp/image /mnt
resize2fs /dev/loop0 262145
resize2fs /dev/loop0 300000

Fix the problem by properly including s_first_data_block into the
computed number of filesystem blocks.

CC: stable@vger.kernel.org
Fixes: 1c6bd7173d66 "ext4: convert file system to meta_bg if needed..."
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/resize.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 48421de803b7..3d9b18505c0c 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1960,7 +1960,8 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 				le16_to_cpu(es->s_reserved_gdt_blocks);
 			n_group = n_desc_blocks * EXT4_DESC_PER_BLOCK(sb);
 			n_blocks_count = (ext4_fsblk_t)n_group *
-				EXT4_BLOCKS_PER_GROUP(sb);
+				EXT4_BLOCKS_PER_GROUP(sb) +
+				le32_to_cpu(es->s_first_data_block);
 			n_group--; /* set to last group number */
 		}
 
-- 
2.16.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: Fix crash during online resizing
  2019-01-24 16:26 [PATCH] ext4: Fix crash during online resizing Jan Kara
@ 2019-02-11 18:43 ` Theodore Y. Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Y. Ts'o @ 2019-02-11 18:43 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, stable

On Thu, Jan 24, 2019 at 05:26:06PM +0100, Jan Kara wrote:
> When computing maximum size of filesystem possible with given number of
> group descriptor blocks, we forget to include s_first_data_block into
> the number of blocks. Thus for filesystems with non-zero
> s_first_data_block it can happen that computed maximum filesystem size
> is actually lower than current filesystem size which confuses the code
> and eventually leads to a BUG_ON in ext4_alloc_group_tables() hitting on
> flex_gd->count == 0. The problem can be reproduced like:
> 
> truncate -s 100g /tmp/image
> mkfs.ext4 -b 1024 -E resize=262144 /tmp/image 32768
> mount -t ext4 -o loop /tmp/image /mnt
> resize2fs /dev/loop0 262145
> resize2fs /dev/loop0 300000
> 
> Fix the problem by properly including s_first_data_block into the
> computed number of filesystem blocks.
> 
> CC: stable@vger.kernel.org
> Fixes: 1c6bd7173d66 "ext4: convert file system to meta_bg if needed..."
> Signed-off-by: Jan Kara <jack@suse.cz>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-24 16:26 [PATCH] ext4: Fix crash during online resizing Jan Kara
2019-02-11 18:43 ` Theodore Y. Ts'o

Stable Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ https://lore.kernel.org/stable \
		stable@vger.kernel.org stable@archiver.kernel.org
	public-inbox-index stable


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.stable


AGPL code for this site: git clone https://public-inbox.org/ public-inbox