io_uring/kbuf: fix unintentional sign extension on shift of reg.bgid
authorColin Ian King <colin.i.king@gmail.com>
Wed, 4 Dec 2024 15:39:23 +0000 (15:39 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 16 Dec 2024 13:58:15 +0000 (06:58 -0700)
commit8131b436b4c8153e2904df37c3aa0aea7aa896a6
tree3e5bd3cb508ee85f8e27e5886e93cf974d6b94ae
parent8d9ef9f8f369424c1633e745c48f95641b375e13
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: ff4afde8a61f ("io_uring/kbuf: use region api for pbuf rings")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Link: https://lore.kernel.org/r/20241204153923.401674-1-colin.i.king@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/kbuf.c