Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3364214ybb; Tue, 31 Mar 2020 03:51:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtiKmDyAt66fzXYsmPt4KpLT+Xqe0qDYzspzF8nL3YkWCA8qnmtyJIp5HXz6rtXqDGTX16v X-Received: by 2002:a05:6830:19ce:: with SMTP id p14mr12104778otp.362.1585651886945; Tue, 31 Mar 2020 03:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585651886; cv=none; d=google.com; s=arc-20160816; b=FGkqwHh52lN/D44i1zncAybNOfzcV2iH/lRqsH3rWExVE0K+CkGPzFRTDeBNxkLMz6 76rYTjledjLu/SFP+qEl6ONnICot1uccc5ct9vvlMwup3q+1EtVw4YRz+EZHVyrq/Y2B mnepWJe170iO/04NlZcgg2jNFkbKb0YO/GE9jIFDEMnaScYlLUOWLoHhM3GVupRORHx8 f07anRTPbftiPxLdFydcuNwMngt6Je3rFyk8hE86tfdtLL8ZPJZkciF9CWO7OWqZsGlQ IdLEzg/QVH3XOZsI2xTPz0CRftDqxt1VSoJw8jMADguK4tQqipmoPnc/3SfcnIWNfn2k IImw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=d4J4PJklSj32QglsV8RKoszWa2qruCPGDcI7VVUz5ZA=; b=DmppcrxvtZIgdkbOBSPdgy+/R2FKgWypc6p2m+/5FcN0L3e9izx1ZlZstm6o7CcQF1 YeuUTIpOFuEFs4lf1ZFPFX7XkAHb3CfXURYFmMIq28RU0yBb80GyQ2i0WHZtZe+bzOe3 IZ0WJvCMHcC/ZJj5xXqOWkpmaa0B7bIAGndU9JbhnaONDmbKcHskT9R8Ck9gMIS9tBV1 shC144LDt+YmX2Zo/zdJb+KpsIzC+J9JaIpF5+MsXf9S62l2zvwJiS5PWo9bipf4r7h6 vWVyO4lRTIFCKoaY1v67+unLKudqvJuQPP7c9OyUMMQzp7L3t54ASSjYD1oQC9aUJbqZ IvJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 a6si7699687oto.34.2020.03.31.03.51.03; Tue, 31 Mar 2020 03:51:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730410AbgCaKu0 (ORCPT + 99 others); Tue, 31 Mar 2020 06:50:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:51652 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730334AbgCaKu0 (ORCPT ); Tue, 31 Mar 2020 06:50:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B4A1BAD9A; Tue, 31 Mar 2020 10:50:24 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 5EF481E1214; Tue, 31 Mar 2020 12:50:24 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Dmitry Monakhov , Jan Kara , stable@vger.kernel.org Subject: [PATCH] ext4: Do not zeroout extents beyond i_disksize Date: Tue, 31 Mar 2020 12:50:16 +0200 Message-Id: <20200331105016.8674-1-jack@suse.cz> X-Mailer: git-send-email 2.16.4 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org We do not want to create initialized extents beyond end of file because for e2fsck it is impossible to distinguish them from a case of corrupted file size / extent tree and so it complains like: Inode 12, i_size is 147456, should be 163840. Fix? no Code in ext4_ext_convert_to_initialized() and ext4_split_convert_extents() try to make sure it does not create initialized extents beyond inode size however they check against inode->i_size which is wrong. They should instead check against EXT4_I(inode)->i_disksize which is the current inode size on disk. That's what e2fsck is going to see in case of crash before all dirty data is written. This bug manifests as generic/456 test failure (with recent enough fstests where fsx got fixed to properly pass FALLOC_KEEP_SIZE_FL flags to the kernel) when run with dioread_lock mount option. CC: stable@vger.kernel.org Fixes: 21ca087a3891 ("ext4: Do not zero out uninitialized extents beyond i_size") Signed-off-by: Jan Kara --- fs/ext4/extents.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 954013d6076b..c5e190fd4589 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3532,8 +3532,8 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, (unsigned long long)map->m_lblk, map_len); sbi = EXT4_SB(inode->i_sb); - eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >> - inode->i_sb->s_blocksize_bits; + eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1) + >> inode->i_sb->s_blocksize_bits; if (eof_block < map->m_lblk + map_len) eof_block = map->m_lblk + map_len; @@ -3785,8 +3785,8 @@ static int ext4_split_convert_extents(handle_t *handle, __func__, inode->i_ino, (unsigned long long)map->m_lblk, map->m_len); - eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >> - inode->i_sb->s_blocksize_bits; + eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1) + >> inode->i_sb->s_blocksize_bits; if (eof_block < map->m_lblk + map->m_len) eof_block = map->m_lblk + map->m_len; /* -- 2.16.4