Skip to content

Commit 77d8c8d

Browse files
iqbalcodes6602axboe
authored andcommitted
io_uring: cast id to u64 before shifting in io_allocate_rbuf_ring()
Smatch warns: io_uring/zcrx.c:393 io_allocate_rbuf_ring() warn: should 'id << 16' be a 64 bit type? The expression 'id << IORING_OFF_PBUF_SHIFT' is evaluated using 32-bit arithmetic because id is a u32. This may overflow before being promoted to the 64-bit mmap_offset. Cast id to u64 before shifting to ensure the shift is performed in 64-bit arithmetic. Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://patch.msgid.link/52400e1b343691416bef3ed3ae287fb1a88d407f.1774780198.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a9d0084 commit 77d8c8d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

io_uring/zcrx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int io_allocate_rbuf_ring(struct io_ring_ctx *ctx,
384384
return -EINVAL;
385385

386386
mmap_offset = IORING_MAP_OFF_ZCRX_REGION;
387-
mmap_offset += id << IORING_OFF_PBUF_SHIFT;
387+
mmap_offset += (u64)id << IORING_OFF_PBUF_SHIFT;
388388

389389
ret = io_create_region(ctx, &ifq->rq_region, rd, mmap_offset);
390390
if (ret < 0)

0 commit comments

Comments
 (0)