mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] io_uring/dma-buf: reject dma-bufs larger than UINT_MAX
@ 2026-12-01  6:39 Bilal Hashim
       [not found] ` <CGME20261203051712epcas5p4c1e58cf6006d0e5e48c5487482eb8fca@epcas5p4.samsung.com>
  2026-12-03 12:19 ` Pavel Begunkov
  0 siblings, 2 replies; 3+ messages in thread
From: Bilal Hashim @ 2026-12-01  6:39 UTC (permalink / raw)
  To: Jens Axboe, Pavel Begunkov; +Cc: io-uring, linux-kernel

__io_register_dmabuf() currently validates dmabuf->size using
io_validate_user_buf_range(0, dmabuf->size), which permits buffers up to
SZ_1T (1 TiB) on 64-bit systems.

However, when dma-buf I/O is submitted to the block layer,
bio_iov_iter_set() assigns the 64-bit iter->iov_offset directly into
bio->bi_iter.bi_offset, which is a 32-bit unsigned int in struct
bvec_iter. Similarly, nvme_rq_setup_dmabuf_map() computes the DMA page
index from the 32-bit bi_offset, and bio splitting/advancement performs
32-bit arithmetic on bi_offset.

If userspace registers a dma-buf larger than 4 GiB and submits fixed
read/write requests at an offset >= 4 GiB (or crossing the 4 GiB
boundary), bi_offset silently truncates modulo 4 GiB, causing NVMe DMA
to access the wrong region of the dma-buf and corrupt data.

Reject dma-bufs whose size exceeds UINT_MAX during registration in
__io_register_dmabuf().

Found by manual code inspection.

Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
 io_uring/dma-buf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index 61825d5..06c223f 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -43,6 +43,10 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
 		dmabuf = NULL;
 		goto err;
 	}
+	if (dmabuf->size > UINT_MAX) {
+		ret = -EOVERFLOW;
+		goto err;
+	}
 	ret = io_validate_user_buf_range(0, dmabuf->size);
 	if (ret)
 		goto err;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] io_uring/dma-buf: reject dma-bufs larger than UINT_MAX
       [not found] ` <CGME20261203051712epcas5p4c1e58cf6006d0e5e48c5487482eb8fca@epcas5p4.samsung.com>
@ 2026-12-03  5:15   ` Anuj Gupta
  0 siblings, 0 replies; 3+ messages in thread
From: Anuj Gupta @ 2026-12-03  5:15 UTC (permalink / raw)
  To: Bilal Hashim; +Cc: Jens Axboe, Pavel Begunkov, io-uring, linux-kernel

On Tue, Dec 01, 2026 at 02:39:09PM +0800, Bilal Hashim wrote:
> Reject dma-bufs whose size exceeds UINT_MAX during registration in
> __io_register_dmabuf().

The block layer already rejects this at registration, in
blkdev_init_dma_buf_io_ctx(). Adding checks for block layer
limitations in io_uring is not a great idea anyway.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] io_uring/dma-buf: reject dma-bufs larger than UINT_MAX
  2026-12-01  6:39 [PATCH] io_uring/dma-buf: reject dma-bufs larger than UINT_MAX Bilal Hashim
       [not found] ` <CGME20261203051712epcas5p4c1e58cf6006d0e5e48c5487482eb8fca@epcas5p4.samsung.com>
@ 2026-12-03 12:19 ` Pavel Begunkov
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2026-12-03 12:19 UTC (permalink / raw)
  To: Bilal Hashim, Jens Axboe; +Cc: io-uring, linux-kernel

On 12/1/26 06:39, Bilal Hashim wrote:
> __io_register_dmabuf() currently validates dmabuf->size using
> io_validate_user_buf_range(0, dmabuf->size), which permits buffers up to
> SZ_1T (1 TiB) on 64-bit systems.

As Anuj mentioned, it's a problem of the block layer and
Keith already patched it there.

> However, when dma-buf I/O is submitted to the block layer,
> bio_iov_iter_set() assigns the 64-bit iter->iov_offset directly into
> bio->bi_iter.bi_offset, which is a 32-bit unsigned int in struct
> bvec_iter. Similarly, nvme_rq_setup_dmabuf_map() computes the DMA page
> index from the 32-bit bi_offset, and bio splitting/advancement performs
> 32-bit arithmetic on bi_offset.
> 
> If userspace registers a dma-buf larger than 4 GiB and submits fixed
> read/write requests at an offset >= 4 GiB (or crossing the 4 GiB
> boundary), bi_offset silently truncates modulo 4 GiB, causing NVMe DMA
> to access the wrong region of the dma-buf and corrupt data.

-- 
Pavel Begunkov


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-03 12:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  6:39 [PATCH] io_uring/dma-buf: reject dma-bufs larger than UINT_MAX Bilal Hashim
     [not found] ` <CGME20261203051712epcas5p4c1e58cf6006d0e5e48c5487482eb8fca@epcas5p4.samsung.com>
2026-12-03  5:15   ` Anuj Gupta
2026-12-03 12:19 ` Pavel Begunkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®