Skip to content

Commit 8ede3db

Browse files
Dan Carpenteraxboe
authored andcommitted
io_uring/net: fix overflow check in io_recvmsg_mshot_prep()
The "controllen" variable is type size_t (unsigned long). Casting it to int could lead to an integer underflow. The check_add_overflow() function considers the type of the destination which is type int. If we add two positive values and the result cannot fit in an integer then that's counted as an overflow. However, if we cast "controllen" to an int and it turns negative, then negative values *can* fit into an int type so there is no overflow. Good: 100 + (unsigned long)-4 = 96 <-- overflow Bad: 100 + (int)-4 = 96 <-- no overflow I deleted the cast of the sizeof() as well. That's not a bug but the cast is unnecessary. Fixes: 9b0fc3c ("io_uring: fix types in io_recvmsg_multishot_overflow") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/138bd2e2-ede8-4bcc-aa7b-f3d9de167a37@moroto.mountain Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 86bcacc commit 8ede3db

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

io_uring/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,10 @@ static int io_recvmsg_mshot_prep(struct io_kiocb *req,
559559

560560
if (unlikely(namelen < 0))
561561
return -EOVERFLOW;
562-
if (check_add_overflow((int)sizeof(struct io_uring_recvmsg_out),
562+
if (check_add_overflow(sizeof(struct io_uring_recvmsg_out),
563563
namelen, &hdr))
564564
return -EOVERFLOW;
565-
if (check_add_overflow(hdr, (int)controllen, &hdr))
565+
if (check_add_overflow(hdr, controllen, &hdr))
566566
return -EOVERFLOW;
567567

568568
iomsg->namelen = namelen;

0 commit comments

Comments
 (0)