Commit 348d25516523 for kernel
commit 348d25516523c3edfec477d56abde2b2491dbf9d
Author: Zakaria Belkadi <zakaria.belkadi@inria.fr>
Date: Fri Nov 20 20:56:44 2026 +0100
block: bounce user PI when writes may remap reference tags
On an io_uring O_DIRECT write, bio_integrity_map_user() can attach the
caller's protection information (PI) buffer directly to the bio. The
block layer pins the pages for reading, but reference-tag remapping can
write to those same pages.
A caller with write access to a block device whose integrity profile
enables reference-tag remapping can therefore modify a page it can
only map for reading. In testing, remapping changed a tag in the page
cache of a read-only file. With a PI buffer backed by the shared zero
page, the kernel faulted during remapping.
Use the existing bounce-buffer path for REQ_OP_WRITE when the queue's
integrity profile has BLK_INTEGRITY_REF_TAG set. This copies the PI
buffer into kernel memory before remapping, so the caller's buffer
retains its original reference tags.
I found this issue during a source review assisted by an LLM.
Fixes: 3d8b5a22d404 ("block: add support to pass user meta buffer")
Cc: stable@vger.kernel.org
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Zakaria Belkadi <zakaria.belkadi@inria.fr>
Reviewed-by: Martin K. Petersen <mkp@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
Link: https://patch.msgid.link/20261120195644.19511-1-zakaria.belkadi@inria.fr
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index d3df726e0f08..aaea5802ecd5 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -394,6 +394,11 @@ int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter)
copy = iov_iter_alignment(iter) &
blk_lim_dma_alignment_and_pad(&q->limits);
+ /* Reference-tag remapping must operate on a private copy of user PI. */
+ if (bio_op(bio) == REQ_OP_WRITE &&
+ (q->limits.integrity.flags & BLK_INTEGRITY_REF_TAG))
+ copy = true;
+
if (blk_queue_pci_p2pdma(q))
extraction_flags |= ITER_ALLOW_P2PDMA;