* [PATCH v2] block: bounce user PI when writes may remap reference tags
@ 2026-11-20 19:56 Zakaria Belkadi
2026-11-21 0:07 ` Caleb Sander Mateos
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Zakaria Belkadi @ 2026-11-20 19:56 UTC (permalink / raw)
To: Jens Axboe
Cc: Christoph Hellwig, Caleb Sander Mateos, Keith Busch, linux-block,
linux-kernel, stable, Kanchan Joshi, Anuj Gupta, florence.schadle,
frederic.tronel, louis.rilling
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>
---
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@inria.fr/
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] block: bounce user PI when writes may remap reference tags
2026-11-20 19:56 [PATCH v2] block: bounce user PI when writes may remap reference tags Zakaria Belkadi
@ 2026-11-21 0:07 ` Caleb Sander Mateos
2026-11-21 0:15 ` Christoph Hellwig
2026-11-21 3:16 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Caleb Sander Mateos @ 2026-11-21 0:07 UTC (permalink / raw)
To: Zakaria Belkadi
Cc: Jens Axboe, Christoph Hellwig, Keith Busch, linux-block,
linux-kernel, stable, Kanchan Joshi, Anuj Gupta, florence.schadle,
frederic.tronel, louis.rilling
On Fri, Nov 20, 2026 at 11:56 AM Zakaria Belkadi
<zakaria.belkadi@inria.fr> 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@vger.kernel.org
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Signed-off-by: Zakaria Belkadi <zakaria.belkadi@inria.fr>
This approach also looks good, thanks.
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
> 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@inria.fr/
>
> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] block: bounce user PI when writes may remap reference tags
2026-11-20 19:56 [PATCH v2] block: bounce user PI when writes may remap reference tags Zakaria Belkadi
2026-11-21 0:07 ` Caleb Sander Mateos
@ 2026-11-21 0:15 ` Christoph Hellwig
2026-11-21 3:16 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-11-21 0:15 UTC (permalink / raw)
To: Zakaria Belkadi
Cc: Jens Axboe, Christoph Hellwig, Caleb Sander Mateos, Keith Busch,
linux-block, linux-kernel, stable, Kanchan Joshi, Anuj Gupta,
florence.schadle, frederic.tronel, louis.rilling
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] block: bounce user PI when writes may remap reference tags
2026-11-20 19:56 [PATCH v2] block: bounce user PI when writes may remap reference tags Zakaria Belkadi
2026-11-21 0:07 ` Caleb Sander Mateos
2026-11-21 0:15 ` Christoph Hellwig
@ 2026-11-21 3:16 ` Martin K. Petersen
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2026-11-21 3:16 UTC (permalink / raw)
To: Zakaria Belkadi
Cc: Jens Axboe, Christoph Hellwig, Caleb Sander Mateos, Keith Busch,
linux-block, linux-kernel, stable, Kanchan Joshi, Anuj Gupta,
florence.schadle, frederic.tronel, louis.rilling
Zakaria,
> + /* 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;
> +
Reviewed-by: Martin K. Petersen <mkp@kernel.org>
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-21 3:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 19:56 [PATCH v2] block: bounce user PI when writes may remap reference tags Zakaria Belkadi
2026-11-21 0:07 ` Caleb Sander Mateos
2026-11-21 0:15 ` Christoph Hellwig
2026-11-21 3:16 ` Martin K. Petersen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.