FAILED: patch "[PATCH] block: restore the iterator when rejecting a misaligned bio" failed to apply to 7.3-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 7.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.3.y
git checkout FETCH_HEAD
git cherry-pick -x 40d070cbb1906896d6fd65c39722d2411830ed9f
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 7.3.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 40d070cbb1906896d6fd65c39722d2411830ed9f Mon Sep 17 00:00:00 2001
From: Andrew Morton <[email protected]>
Date: Sun, 18 Oct 2026 17:30:00 -0700
Subject: [PATCH] block: restore the iterator when rejecting a misaligned bio
bio_iov_iter_get_pages() can extract some iovecs before encountering a misaligned one. It releases the pages and rejects the entire bio, but leaves the supplied iterator advanced.
An iomap direct-I/O caller may subsequently reexpand the iterator's byte count and fall back to buffered I/O. The reexpanded count then includes bytes before the iterator's current segment, potentially causing iterate_iovec() to read beyond the imported iovec array.
In a reproducer using an initial empty iovec followed by 10-byte and 1015-byte segments, writev() returned 1015 instead of 1025 and KASAN reported an 8-byte read beyond the nine-element iovec allocation. Saving and restoring the iterator on the rejected-bio path makes writev() return 1025 and eliminates the KASAN report.
Restore the entire iterator rather than reverting a byte count:
advancing past an empty segment changes its position without consuming any bytes.
Leave successful and partially accepted bio paths unchanged.
--- block/bio.c | 3 +++ 1 file changed, 3 insertions(+)
block/bio.c +3 -0
@@ -1311,6 +1311,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter, unsigned mem_align_mask, unsigned len_align_mask) {iov_iter_extraction_t flags =0 ; +struct iov_iter saved_iter;int ret;if (WARN_ON_ONCE (bio_flagged (bio,BIO_CLONED )))
@@ -1330,6 +1331,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,if (bio->bi_bdev &&blk_queue_pci_p2pdma (bio->bi_bdev->bd_disk->queue)) flags |=ITER_ALLOW_P2PDMA ; + saved_iter = *iter; do { ssize_t size;
@@ -1371,6 +1373,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,bio_release_pages (bio, false);bio_clear_flag (bio,BIO_PAGE_PINNED ); bio->bi_vcnt =0 ; + *iter = saved_iter;return -EINVAL ; }
Signature · 1 line
2.53.0
PATCH 1/1 block: restore the iterator when rejecting a misaligned bio
From: Andrew Morton <[email protected]>
commit 40d070cbb1906896d6fd65c39722d2411830ed9f upstream.
bio_iov_iter_get_pages() can extract some iovecs before encountering a misaligned one. It releases the pages and rejects the entire bio, but leaves the supplied iterator advanced.
An iomap direct-I/O caller may subsequently reexpand the iterator's byte count and fall back to buffered I/O. The reexpanded count then includes bytes before the iterator's current segment, potentially causing iterate_iovec() to read beyond the imported iovec array.
In a reproducer using an initial empty iovec followed by 10-byte and 1015-byte segments, writev() returned 1015 instead of 1025 and KASAN reported an 8-byte read beyond the nine-element iovec allocation. Saving and restoring the iterator on the rejected-bio path makes writev() return 1025 and eliminates the KASAN report.
Restore the entire iterator rather than reverting a byte count:
advancing past an empty segment changes its position without consuming any bytes.
Leave successful and partially accepted bio paths unchanged.
[ Backport to 7.3.y: restore the iterator in the existing inline
-EINVAL cleanup, as this tree lacks out_release_pages. ]
--- block/bio.c | 3 +++ 1 file changed, 3 insertions(+)
block/bio.c +3 -0
@@ -1285,6 +1285,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter, unsigned mem_align_mask, unsigned len_align_mask) {iov_iter_extraction_t flags =0 ; +struct iov_iter saved_iter;if (WARN_ON_ONCE (bio_flagged (bio,BIO_CLONED )))return -EIO ;
@@ -1303,6 +1304,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,if (bio->bi_bdev &&blk_queue_pci_p2pdma (bio->bi_bdev->bd_disk->queue)) flags |=ITER_ALLOW_P2PDMA ; + saved_iter = *iter; do { ssize_t ret;
@@ -1320,6 +1322,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,bio_release_pages (bio, false);bio_clear_flag (bio,BIO_PAGE_PINNED ); bio->bi_vcnt =0 ; + *iter = saved_iter; }if (!bio->bi_vcnt)return ret;
Signature · 1 line
2.30.2