From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 33F9323EAAA; Tue, 25 Aug 2026 14:01:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666466; cv=none; b=M6zNglbGS8ZDt70OISe4tZT3BO9+DXy9g8E28wW//smG2jKUkcDpsivH6/klBslWWSAvWqHARRoTsMZAEyB5DkTu7tEoWFrGRdqaPsEA+/y1NHCovDJ9f89Ca1EAn6NplXShs1m2rwot5UkZRSHCq2bylDSjKrw1/9F3A/WA/co= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666466; c=relaxed/simple; bh=4RJemLtBR+ncNfR6JZ+TPsGX57Am0ZjANQzYrrtFLgI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jf5KDOHAxMOy5XFAL8AWTyp276huHGslpOnUn7bXJQ/0uKcs07en12U3G+fD061lNzY48tQi8BMVJx4i8miF6hPVMMoDYMu1ps/kquV6G47HxlhnZ9TyUwVOAGHvz87giMV86SPc6VudOQzgNc/mCp6U1nz9eg3zTgRMkuXB2Ks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1SPxHsV4; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1SPxHsV4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 120D61F000E9; Tue, 25 Aug 2026 14:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787666464; bh=gRFsxoV1BqgJMH45I2FYQagDJlg62VftlquzyxQg6Cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1SPxHsV4XUwYs8RDsuiTjrO4mPEaHUEpepuEvvQWVm07zHAXCCqglUolw3DxASwYD 6KVunD+QNO+xM73dieBEYlDgUXh0WFX9Qhmbcml+Ajk6vzqu6HAn91OOWXp4DZugzs NJBeOtvPLn9/g5riq5drV77oBYyriyUljvERQo7w= 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 , "Miguel Gazquez (Schneider Electric)" Subject: [PATCH 5.10 50/57] iomap: adjust read range correctly for non-block-aligned positions Date: Tue, 25 Aug 2026 15:27:12 +0200 Message-ID: <20260825132543.293253592@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260825132541.342390421@linuxfoundation.org> References: <20260825132541.342390421@linuxfoundation.org> User-Agent: quilt/0.69 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 5.10-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 Signed-off-by: Miguel Gazquez (Schneider Electric) 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 219f9e1a26436..5ad3bf906b35a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -103,17 +103,24 @@ iomap_adjust_read_range(struct inode *inode, struct iomap_page *iop, * to avoid reading in already uptodate ranges. */ if (iop) { - 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 (!test_bit(i, iop->uptodate)) 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) */ for ( ; i <= last; i++) { -- 2.53.0