Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1132642pxb; Thu, 19 Aug 2021 21:35:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylI/zVBAbumhYGBgVF7JBboNoooIcgeAKgE8x3V2Ssrp21ItM5GxsEfJpWOrkFkb1pxOp6 X-Received: by 2002:aa7:d916:: with SMTP id a22mr19977216edr.158.1629434119936; Thu, 19 Aug 2021 21:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629434119; cv=none; d=google.com; s=arc-20160816; b=RUanmlALGNeF2MhZUlCHVrf7cifdddeXVlM0Q7/EzrrwmNGy6zkB59x6+hVZOkAOZe O62cmbGJJ2nuKZgaTUEdemerkxZhg8NVZxUfzVxb/vNAsBXo4D+LId4iMIAFM4m0lrSw GxXBjPPzluJiz+6PC0qSQUQ1SIgSV7+vBcz7FmVOVERs9/UQtS1RO8IjR1HEokUbOLUt fPeNgmhM8S0BEsER94EpbDT85xAKJ0BP3aEuNnmuokhXppE3tK40haE4N0x/PQYJeg6k UAros9215EY97k9u0m+jn1JeVlD+rCA/yGMZFhRtk8djpU4XBG+6gzdX2IbMJxRhE+9w 8dQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=N78IgbkMP84C7ViU+8NZYyXPxkCkTs82FhPBYxigois=; b=ZsH2CZfvbbLk6Po+2v2rMCi6iZwhgkqiLEQ/sns9k7aq4ajVuas/YgwnlzUJlcIiif a7QDzlXi7HPeNIbi14AtbhZCQoJVBjRB1eyf8rugSrAOqQSGe9qWG4SvRcidHhMbM/mL eQg9LLIVOYqSu/bfaDVoFw2EsORsOnPILx99ONdo3ZcTH7GE1OJJo7dpT+QFroIEsEBV +0cI4essWdSu/vC72wYlncoX5qyy7PSYQoHt4odDwTDBrHArmiKvgfEnqGp8gdxviETW m4hMzB+qNWxTrGHDTU21zEk6CLLFVud1S9JweUfUXa4lWOAVRoMMV3K+WCtyjYWPpnBC lFog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mq21si5381496ejc.409.2021.08.19.21.34.48; Thu, 19 Aug 2021 21:35:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232629AbhHTEc4 (ORCPT + 99 others); Fri, 20 Aug 2021 00:32:56 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:17991 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232578AbhHTEcy (ORCPT ); Fri, 20 Aug 2021 00:32:54 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GrTCd2Pcqzbg1S; Fri, 20 Aug 2021 12:28:29 +0800 (CST) Received: from dggpeml500025.china.huawei.com (7.185.36.35) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 20 Aug 2021 12:32:15 +0800 Received: from huawei.com (10.175.124.27) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 20 Aug 2021 12:32:14 +0800 From: Hou Tao To: , , CC: , Subject: [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV Date: Fri, 20 Aug 2021 12:45:05 +0800 Message-ID: <20210820044505.474318-1-houtao1@huawei.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500025.china.huawei.com (7.185.36.35) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the newly-added blocks, but the limit on the max value of ee_len field is ignored, and it can lead to BUG_ON as shown below when running command "fallocate -l 128M file" on a fast_commit-enabled fs: kernel BUG at fs/ext4/ext4_extents.h:199! invalid opcode: 0000 [#1] SMP PTI CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200 Call Trace: ? ext4_fc_write_inode+0xf2/0x150 ext4_fc_commit+0x93b/0xa00 ? ext4_fallocate+0x1ad/0x10d0 ext4_sync_file+0x157/0x340 ? ext4_sync_file+0x157/0x340 vfs_fsync_range+0x49/0x80 do_fsync+0x3d/0x70 __x64_sys_fsync+0x14/0x20 do_syscall_64+0x3b/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae Simply fixing it by limiting the number of blocks in one EXT4_FC_TAG_ADD_RANGE TLV. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Signed-off-by: Hou Tao --- fs/ext4/fast_commit.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index e8195229c252..782d05a3f97a 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -893,6 +893,12 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc) sizeof(lrange), (u8 *)&lrange, crc)) return -ENOSPC; } else { + unsigned int max = (map.m_flags & EXT4_MAP_UNWRITTEN) ? + EXT_UNWRITTEN_MAX_LEN : EXT_INIT_MAX_LEN; + + /* Limit the number of blocks in one extent */ + map.m_len = min(max, map.m_len); + fc_ext.fc_ino = cpu_to_le32(inode->i_ino); ex = (struct ext4_extent *)&fc_ext.fc_ex; ex->ee_block = cpu_to_le32(map.m_lblk); -- 2.29.2