Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3804531pxb; Mon, 4 Oct 2021 09:58:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgwo9g8Ywf9qJ3Lzn9i68QD8T71h+3YrzRS5qJj3rkyu+oLgpnB3AedWcdzaslRyBxs38F X-Received: by 2002:a17:902:a503:b029:12b:2429:385e with SMTP id s3-20020a170902a503b029012b2429385emr688554plq.64.1633366699177; Mon, 04 Oct 2021 09:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633366699; cv=none; d=google.com; s=arc-20160816; b=vEShSF4FODJO5fMBc7tyMH2DSuT9kozz7kxr2udd9sQtrkfjnNIs0ixRWpCssuMxf9 PklNSJcoUE/UU5U9FTgwVrKJ0P+0Edx13nb1beNrPvq7LywpVAFmHOMQvXkGSS0UQwju TJa90L6OUrIoU5UtKSEnDMQFVnzR5/fF6fspzzGJVOj6Anp3k4gWDZkDfETTyMT3KxqU k3pcvl+tkeKO5w94768VkQeDhd3sOEvZm87t0ySZX0TDMbcoFljDp71gZp5bOeU9/t70 U45rwJI1LZJNxeL/tb8g1zHsPJGEOKw4FiwrR3E0djk8Pg6IivFepJ4alUOqw/ZW/EvH vpMg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0CMKXLTiT6k9XMXLzqkAKD6UfCqJn0RD01u8vyRBIhw=; b=h1VQjO9eqk86hnZkY4BgvoSJYs1MVuQQZ7yK2nKRADC6w+uOA58PIgmQxUGM0u7ggN DhsPpviQODJUwFtc/DW8SGf/WKdLxRM8dN5YfSlUG822RBJNi/X569JhVxWvN84+f3pO 86rQeUecvU9jaBHZ5eMgdguDmej279B0H2ytDsIcEGH6w4e8IZed86NJgs6i7tJ5f1PN WCUkrEUFW+JWhjgsvxL+/rcS3mhXAQgS9SXvVejo44bEesffvpOCgXQPhJgSWuhXdxdU 1PV+FP8S811jlv7HnM02mlsHpj/0UeVNFj7L+H8AbhxfU98+2c5QcHD+4v1zn5lX05Z8 trAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="taRXdU/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lx2si17130237pjb.182.2021.10.04.09.58.06; Mon, 04 Oct 2021 09:58:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="taRXdU/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238352AbhJDNmE (ORCPT + 99 others); Mon, 4 Oct 2021 09:42:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:51850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238356AbhJDNkU (ORCPT ); Mon, 4 Oct 2021 09:40:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D55F861501; Mon, 4 Oct 2021 13:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353504; bh=2qsfbws95ldWgWaAEjuk+CYl+0H/cNEXWLareyVg+tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=taRXdU/jVnJmxmgmg4YDey2rD/Z2nsKbe9od7NmQXBg+LN7C5MiQHD+HMA12pgUPl YDq7Bhu7fPbkv/5OX0TbvoPMIWPXccK/Uig7zrnSrx3NTdEq3Zr5TtnwmE5IX46A/u 6x+RqO8biO5+7LBKqfbfsF+6ZbdcGnx6Jza5Z6ws= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Hou Tao , Theodore Tso Subject: [PATCH 5.14 154/172] ext4: limit the number of blocks in one ADD_RANGE TLV Date: Mon, 4 Oct 2021 14:53:24 +0200 Message-Id: <20211004125049.944161646@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hou Tao commit a2c2f0826e2b75560b31daf1cd9a755ab93cf4c6 upstream. 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") Cc: stable@kernel.org Signed-off-by: Hou Tao Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210820044505.474318-1-houtao1@huawei.com Signed-off-by: Greg Kroah-Hartman --- fs/ext4/fast_commit.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -893,6 +893,12 @@ static int ext4_fc_write_inode_data(stru 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);