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 28628335BAA; Mon, 18 Aug 2025 13:20:26 +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=1755523226; cv=none; b=VRDzQ42EZE6LDUUIjSNogqIz09fyC4LhyilBV2ocW6thNHzCtM5yKwhrIjyTD/72YetwDWbhDVW1hHbmD8F4FNTJJ8vfb+lfDX4wjThUVp81XtaIWRiotrcALMYYJZW9nO+1nSLFmAW7BpvZNQjlKru0uiKJIbtuJGkcljNBuMo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755523226; c=relaxed/simple; bh=xfbET6pvnQ+cQdEyXyJ7XMxD8PFKKhha1y/InO/+G0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lEUwlu5ImGFipnjuEIbViWxwflrmOamZ21yDAKSbCxz9Qo30KwMXT1bh26XoYFJ1LP+7LZ6/mfeiMlyPGDNxtIzU9NGZg9C+k+dZdIf5T4N4FCByt2G62rWKbZBDXRgXvh2hxpPno3tkv5sAi5TP7JbL1i0vE0sAbHcMEOd1Oqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kdZSVRti; 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="kdZSVRti" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A09A2C4CEEB; Mon, 18 Aug 2025 13:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755523226; bh=xfbET6pvnQ+cQdEyXyJ7XMxD8PFKKhha1y/InO/+G0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kdZSVRti3gc58HBejD7Pr/Dlh3Ha48Jm5ATwsa0n5q0EFDiD6NnJ3heOvpRa0S51P GSRME5V9A9KbnZazpb9ajt1Y/nAPw0GDP9t4e/1RGOly3c4gcnCVr4tUfwoHckYqop Tja2UaTl0uQ9MIDwZSkxDZ9VupiQ52xYO7pIDACw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wei Gao , Jan Kara , Sasha Levin Subject: [PATCH 6.15 108/515] ext2: Handle fiemap on empty files to prevent EINVAL Date: Mon, 18 Aug 2025 14:41:34 +0200 Message-ID: <20250818124502.519368757@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250818124458.334548733@linuxfoundation.org> References: <20250818124458.334548733@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wei Gao [ Upstream commit a099b09a3342a0b28ea330e405501b5b4d0424b4 ] Previously, ext2_fiemap would unconditionally apply "len = min_t(u64, len, i_size_read(inode));", When inode->i_size was 0 (for an empty file), this would reduce the requested len to 0. Passing len = 0 to iomap_fiemap could then result in an -EINVAL error, even for valid queries on empty files. Link: https://github.com/linux-test-project/ltp/issues/1246 Signed-off-by: Wei Gao Signed-off-by: Jan Kara Link: https://patch.msgid.link/20250613152402.3432135-1-wegao@suse.com Signed-off-by: Sasha Levin --- fs/ext2/inode.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 30f8201c155f..177b1f852b63 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -895,9 +895,19 @@ int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len) { int ret; + loff_t i_size; inode_lock(inode); - len = min_t(u64, len, i_size_read(inode)); + i_size = i_size_read(inode); + /* + * iomap_fiemap() returns EINVAL for 0 length. Make sure we don't trim + * length to 0 but still trim the range as much as possible since + * ext2_get_blocks() iterates unmapped space block by block which is + * slow. + */ + if (i_size == 0) + i_size = 1; + len = min_t(u64, len, i_size); ret = iomap_fiemap(inode, fieinfo, start, len, &ext2_iomap_ops); inode_unlock(inode); -- 2.39.5