Re: [PATCH v2] block: bounce user PI when writes may remap reference tags
From: Caleb Sander Mateos
Date: Fri Nov 20 2026 - 19:08:10 EST
On Fri, Nov 20, 2026 at 11:56 AM Zakaria Belkadi
<zakaria.belkadi@xxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxx
> Suggested-by: Christoph Hellwig <hch@xxxxxxxxxxxxx>
> Signed-off-by: Zakaria Belkadi <zakaria.belkadi@xxxxxxxx>
This approach also looks good, thanks.
Reviewed-by: Caleb Sander Mateos <csander@xxxxxxxxxxxxxxx>
> ---
> v2:
> - Bounce the user PI buffer instead of pinning it for writing (Christoph).
> - Dropped Caleb's Reviewed-by, since the patch changed.
> - Corrected what the caller controls (Caleb): it chooses the address of
> the PI buffer, the seed and the device offset, so both where the tag
> is stored and its value.
>
> v1: https://lore.kernel.org/linux-block/20261118154053.13218-1-zakaria.belkadi@xxxxxxxx/
>
> Open question on stacked devices: the test uses the profile of the
> top-level queue. By my reading of the source, a device-mapper target
> with members of different profiles can get a top-level profile without
> BLK_INTEGRITY_REF_TAG while a member has it, because
> dm_set_device_limits() ignores a stacking mismatch. This condition
> would then not force a bounce. I have not tested whether such a
> configuration can accept user PI and reach reference-tag remapping on
> the underlying device.
>
> Would you prefer bouncing all user PI buffers on writes to cover this
> case?
>
> Tested on v7.4-rc3 in a QEMU guest, emulated NVMe namespace with
> T10-DIF type 1, as an unprivileged user who owns only the device node:
> - PI buffer = read-only mapping of a root-owned file: without the patch
> the reference tag in the file changes; with it the write succeeds and
> the file is unchanged.
> - PI buffer = shared zero page: without the patch the kernel oopses in
> blk_integrity_remap(); with it the write succeeds with no fault.
> - Writable PI buffers still work, and the kernel no longer modifies
> them.
> - Stored tags (as root): a write with a seed different from the block
> number succeeds with reference-tag checking enabled. A subsequent
> read using the block number as the seed returns the expected remapped
> tags, with identical results before and after the patch.
>
> block/bio-integrity.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/block/bio-integrity.c b/block/bio-integrity.c
> index d3df726e0..aaea5802e 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;
>
>
> base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
> --
> 2.39.5
>