]> git.itanic.dy.fi Git - linux-stable/commit
io_uring/net: fix overflow check in io_recvmsg_mshot_prep()
authorDan Carpenter <dan.carpenter@linaro.org>
Fri, 1 Mar 2024 15:29:39 +0000 (18:29 +0300)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:16:29 +0000 (18:16 -0400)
commitb6563ad0d599110bd5cf8f56c47d279c3ed796fe
tree17ec51b41d4a57a157b030df147daed36f34635c
parent0bcd9ff68d446e8333f668a9c64baeb75ee7cc41
io_uring/net: fix overflow check in io_recvmsg_mshot_prep()

[ Upstream commit 8ede3db5061bb1fe28e2c9683329aafa89d2b1b4 ]

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: 9b0fc3c054ff ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
io_uring/net.c