From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82213255F5C; Wed, 30 Jul 2025 09:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753868855; cv=none; b=JsYtY5bNEgZYHtIqVWvtNHm3/GhbRgjirebj/jOvvpoEFJ0qnwVWhmnL8/zDjNxFIsqIZYYorXJo5pU0WKAR+OKfPE9htAqF8ZvfEzEueDEAlkEVSzq/AWH6B+wtleJBu/+OLjFmnZhYE73BgOXPgElMOMRXnwzxsHgZ9j8Vv54= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753868855; c=relaxed/simple; bh=ykegQ4r5Y7sw2UYVssGFsrLQ6Kv0tEKBZTIuUgpynwU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DesZLe2AK72jVIEVoLuUxKQMywxlUApEx4dDLprnaVC0BtguaetoqD0W3G1YLFLSgDqRCAuzeLGpkRNMvP271t22y9+58qyRDE0Df3BQNpsZnDcp/KDyGsoqFsdAIPFpwmZ/GRJuPt1HTaSib1mPBVHInsTA9sWRwZ8+Op3iuEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KyoqcUjI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="KyoqcUjI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5EBEC4CEF5; Wed, 30 Jul 2025 09:47:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1753868855; bh=ykegQ4r5Y7sw2UYVssGFsrLQ6Kv0tEKBZTIuUgpynwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KyoqcUjIV1J1d6ty2+S7wFTeTbHu+YUdUPniyJtxqAzUGYfoyqzML+ATCzrc9Xr7y 4/X7lHgLkyJQXHRCtwn3tZt7vJUvc6QYA1KVC8mMLky9l7tlD+e8GKYAKhxxeVeWvs BQDTt4D778vIaW/xGG4NGViH7xKHd1AxAcnFs2k8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhang Yi , Jan Kara , Baokun Li , Theodore Tso , stable@kernel.org, Sasha Levin Subject: [PATCH 6.12 093/117] ext4: fix incorrect punch max_end Date: Wed, 30 Jul 2025 11:36:02 +0200 Message-ID: <20250730093237.409971402@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250730093233.592541778@linuxfoundation.org> References: <20250730093233.592541778@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang Yi [ Upstream commit 29ec9bed2395061350249ae356fb300dd82a78e7 ] For the extents based inodes, the maxbytes should be sb->s_maxbytes instead of sbi->s_bitmap_maxbytes. Additionally, for the calculation of max_end, the -sb->s_blocksize operation is necessary only for indirect-block based inodes. Correct the maxbytes and max_end value to correct the behavior of punch hole. Fixes: 2da376228a24 ("ext4: limit length to bitmap_maxbytes - blocksize in punch_hole") Signed-off-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Baokun Li Link: https://patch.msgid.link/20250506012009.3896990-2-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3992,7 +3992,7 @@ int ext4_punch_hole(struct file *file, l struct inode *inode = file_inode(file); struct super_block *sb = inode->i_sb; ext4_lblk_t start_lblk, end_lblk; - loff_t max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize; + loff_t max_end = sb->s_maxbytes; loff_t end = offset + length; handle_t *handle; unsigned int credits; @@ -4001,14 +4001,20 @@ int ext4_punch_hole(struct file *file, l trace_ext4_punch_hole(inode, offset, length, 0); WARN_ON_ONCE(!inode_is_locked(inode)); + /* + * For indirect-block based inodes, make sure that the hole within + * one block before last range. + */ + if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) + max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize; + /* No need to punch hole beyond i_size */ if (offset >= inode->i_size) return 0; /* * If the hole extends beyond i_size, set the hole to end after - * the page that contains i_size, and also make sure that the hole - * within one block before last range. + * the page that contains i_size. */ if (end > inode->i_size) end = round_up(inode->i_size, PAGE_SIZE);