Skip to content

Commit febfbf7

Browse files
ColinIanKingaxboe
authored andcommitted
io_uring/kbuf: fix unintentional sign extension on shift of reg.bgid
Shifting reg.bgid << IORING_OFF_PBUF_SHIFT results in a promotion from __u16 to a 32 bit signed integer, this is then sign extended to a 64 bit unsigned long on 64 bit architectures. If reg.bgid is greater than 0x7fff then this leads to a sign extended result where all the upper 32 bits of mmap_offset are set to 1. Fix this by casting reg.bgid to the same type as mmap_offset before performing the shift. Fixes: ef62de3 ("io_uring/kbuf: use region api for pbuf rings") Signed-off-by: Colin Ian King <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 546d191 commit febfbf7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

io_uring/kbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
640640
return -ENOMEM;
641641
}
642642

643-
mmap_offset = reg.bgid << IORING_OFF_PBUF_SHIFT;
643+
mmap_offset = (unsigned long)reg.bgid << IORING_OFF_PBUF_SHIFT;
644644
ring_size = flex_array_size(br, bufs, reg.ring_entries);
645645

646646
memset(&rd, 0, sizeof(rd));

0 commit comments

Comments
 (0)