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 788ED1A83ED; Tue, 26 Aug 2025 12:52:08 +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=1756212728; cv=none; b=hesAoBZ3MI5NlDXfdc6He3FPGcsAiKHu/oWoi/CqOSdnWOinaT6KOfO0jCtkWjvuZy78Q1yzXRp6mHeSqblGFJLTKwUJrEhUYwaTXW9Es62L835xObL4oM/EoIDlbrtLXW1C5p++lYUkimjVwCeVsZEK84c5R4CUTBw2dYphl6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756212728; c=relaxed/simple; bh=ikQ18/Zd4dpI+iv6BGQzT/e05zQuX0Quw3DtJkJmiUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XnHkDQvxca/mELxYFxIcSgmccPQCwRUkq9qEh4MoT5BhSA8mEXb/BwP73FRKV4XcMLVjt8RvH1iBPV/AxsFa8Ulx4RQkgILEyV2ipYp1MvNRCx/XQoi/1YofucjBCcdlE8zzMn08Nn6e19uyNipv/hQybNgccpXS9zUPaLg8f8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=J5Edch3I; 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="J5Edch3I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0060C4CEF1; Tue, 26 Aug 2025 12:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756212728; bh=ikQ18/Zd4dpI+iv6BGQzT/e05zQuX0Quw3DtJkJmiUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J5Edch3IAttz1UpRabJxcaKliGhN+WcqBm6McqJP4Hizy6vlaF36FfUjeuhCkQx54 gAIUEjgloJXm71EIMXWfmAh9NlZ8AqnDNB0E6bEy3Hc/sGEPEGkoniwUXzPrn2oh/+ 6+5v4cRKg+gJUgklrkUTNYYx8j08kL3UHow0ddaA= 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.6 079/587] ext2: Handle fiemap on empty files to prevent EINVAL Date: Tue, 26 Aug 2025 13:03:48 +0200 Message-ID: <20250826110954.944931144@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110952.942403671@linuxfoundation.org> References: <20250826110952.942403671@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.6-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 314b415ee518..6ff1f8f29a3c 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