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 531BE346FBD; Tue, 6 Jan 2026 17:16:09 +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=1767719769; cv=none; b=awsWwwpwSOeASrJgjBpeEaoYnVXl7ElrNnAZJGmDDEGyDWImd8bINglXJxgh6z3KUWUoU3Ur9L1qA0JflPz7qT4rbl23eQpShpkqF2lTetZVzqv+ECiPM8R+cm3w32e9+HGIYNe0E1XS3EFiRvHA0aelN5UR27kXBGQSbWs2Bt4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767719769; c=relaxed/simple; bh=O/mVMdBWR6Iyu+LnBkam4F6wq8zeKoPgS5UR24CT/g0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WsZyO5+Yfw1RD8Eb5dzJrQXkQtmkSXlIAfvGhBfvgxD8SjBGTVaITA9SB0jU349TGKpMSiNl55g6OXDWfB/JQzMwO1dQoszP1dPXd+0LkPsGgwxCVdGFSA8/rJmpCPvfeyPgmtlD9Lpm1bLU52agDZl1xhFiX8zkc4GlX9wAq3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hVVUvxXc; 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="hVVUvxXc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6704C116C6; Tue, 6 Jan 2026 17:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1767719769; bh=O/mVMdBWR6Iyu+LnBkam4F6wq8zeKoPgS5UR24CT/g0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVVUvxXc7fiIgTxrgMHvpB+zxEfjGBoOrhO8vlJYrr4VhKHhCJ1oKIpfefZpdLAFT 0nAremsusaW/CrWna5/ikN06aFAlU6bzZMPRvgM5ddRifpV0A39FwgP5WAx01itVgv Mkv1+QU5OAmvfzcTA0y7K2DftmxlHGQvxTZi+Dos= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joanne Koong , syzbot@syzkaller.appspotmail.com, Brian Foster , Christoph Hellwig , Christian Brauner , Sasha Levin Subject: [PATCH 6.12 006/567] iomap: adjust read range correctly for non-block-aligned positions Date: Tue, 6 Jan 2026 17:56:28 +0100 Message-ID: <20260106170451.578026680@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260106170451.332875001@linuxfoundation.org> References: <20260106170451.332875001@linuxfoundation.org> User-Agent: quilt/0.69 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: Joanne Koong [ Upstream commit 7aa6bc3e8766990824f66ca76c19596ce10daf3e ] iomap_adjust_read_range() assumes that the position and length passed in are block-aligned. This is not always the case however, as shown in the syzbot generated case for erofs. This causes too many bytes to be skipped for uptodate blocks, which results in returning the incorrect position and length to read in. If all the blocks are uptodate, this underflows length and returns a position beyond the folio. Fix the calculation to also take into account the block offset when calculating how many bytes can be skipped for uptodate blocks. Signed-off-by: Joanne Koong Tested-by: syzbot@syzkaller.appspotmail.com Reviewed-by: Brian Foster Reviewed-by: Christoph Hellwig Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/iomap/buffered-io.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d4b990938399c..258ac7bf658fd 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -250,17 +250,24 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio, * to avoid reading in already uptodate ranges. */ if (ifs) { - unsigned int i; + unsigned int i, blocks_skipped; /* move forward for each leading block marked uptodate */ - for (i = first; i <= last; i++) { + for (i = first; i <= last; i++) if (!ifs_block_is_uptodate(ifs, i)) break; - *pos += block_size; - poff += block_size; - plen -= block_size; - first++; + + blocks_skipped = i - first; + if (blocks_skipped) { + unsigned long block_offset = *pos & (block_size - 1); + unsigned bytes_skipped = + (blocks_skipped << block_bits) - block_offset; + + *pos += bytes_skipped; + poff += bytes_skipped; + plen -= bytes_skipped; } + first = i; /* truncate len if we find any trailing uptodate block(s) */ while (++i <= last) { -- 2.51.0