* [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep()
@ 2024-03-01 15:28 Dan Carpenter
2024-03-01 15:29 ` [PATCH 1/2] io_uring/net: fix overflow check " Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Dan Carpenter @ 2024-03-01 15:28 UTC (permalink / raw)
To: Dylan Yudaken
Cc: Jens Axboe, Pavel Begunkov, Dylan Yudaken, io-uring, linux-kernel
The casting is problematic and could introduce an integer underflow
issue.
Dan Carpenter (2):
io_uring/net: fix overflow check in io_recvmsg_mshot_prep()
io_uring/net: remove unnecesary check
io_uring/net.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] io_uring/net: fix overflow check in io_recvmsg_mshot_prep()
2024-03-01 15:28 [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Dan Carpenter
@ 2024-03-01 15:29 ` Dan Carpenter
2024-03-01 15:29 ` [PATCH 2/2] io_uring/net: remove unnecessary check Dan Carpenter
2024-03-01 15:55 ` [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Jens Axboe
2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2024-03-01 15:29 UTC (permalink / raw)
To: Dylan Yudaken
Cc: Jens Axboe, Pavel Begunkov, io-uring, linux-kernel,
kernel-janitors
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 <[email protected]>
---
io_uring/net.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index 926d1fb0335d..da257bf429d5 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -559,10 +559,10 @@ static int io_recvmsg_mshot_prep(struct io_kiocb *req,
if (unlikely(namelen < 0))
return -EOVERFLOW;
- if (check_add_overflow((int)sizeof(struct io_uring_recvmsg_out),
+ if (check_add_overflow(sizeof(struct io_uring_recvmsg_out),
namelen, &hdr))
return -EOVERFLOW;
- if (check_add_overflow(hdr, (int)controllen, &hdr))
+ if (check_add_overflow(hdr, controllen, &hdr))
return -EOVERFLOW;
iomsg->namelen = namelen;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] io_uring/net: remove unnecessary check
2024-03-01 15:28 [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Dan Carpenter
2024-03-01 15:29 ` [PATCH 1/2] io_uring/net: fix overflow check " Dan Carpenter
@ 2024-03-01 15:29 ` Dan Carpenter
2024-03-01 16:56 ` Dan Carpenter
2024-03-01 15:55 ` [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Jens Axboe
2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2024-03-01 15:29 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pavel Begunkov, io-uring, linux-kernel, kernel-janitors
"namelen" is type size_t so it can't be negative.
Signed-off-by: Dan Carpenter <[email protected]>
---
io_uring/net.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index da257bf429d5..04a7426c80d2 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -557,8 +557,6 @@ static int io_recvmsg_mshot_prep(struct io_kiocb *req,
(REQ_F_APOLL_MULTISHOT|REQ_F_BUFFER_SELECT)) {
int hdr;
- if (unlikely(namelen < 0))
- return -EOVERFLOW;
if (check_add_overflow(sizeof(struct io_uring_recvmsg_out),
namelen, &hdr))
return -EOVERFLOW;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep()
2024-03-01 15:28 [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Dan Carpenter
2024-03-01 15:29 ` [PATCH 1/2] io_uring/net: fix overflow check " Dan Carpenter
2024-03-01 15:29 ` [PATCH 2/2] io_uring/net: remove unnecessary check Dan Carpenter
@ 2024-03-01 15:55 ` Jens Axboe
2 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2024-03-01 15:55 UTC (permalink / raw)
To: Dylan Yudaken, Dan Carpenter
Cc: Pavel Begunkov, Dylan Yudaken, io-uring, linux-kernel
On Fri, 01 Mar 2024 18:28:40 +0300, Dan Carpenter wrote:
> The casting is problematic and could introduce an integer underflow
> issue.
>
> Dan Carpenter (2):
> io_uring/net: fix overflow check in io_recvmsg_mshot_prep()
> io_uring/net: remove unnecesary check
>
> [...]
Applied, thanks!
[1/2] io_uring/net: fix overflow check in io_recvmsg_mshot_prep()
commit: a69d208854948bc8334a01bc17f13a06a5a977d2
[2/2] io_uring/net: remove unnecessary check
commit: 789748af32c4a6f50db401d46e6a89ab28a6e3ac
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] io_uring/net: remove unnecessary check
2024-03-01 15:29 ` [PATCH 2/2] io_uring/net: remove unnecessary check Dan Carpenter
@ 2024-03-01 16:56 ` Dan Carpenter
2024-03-01 17:23 ` Jens Axboe
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2024-03-01 16:56 UTC (permalink / raw)
To: Jens Axboe; +Cc: Pavel Begunkov, io-uring, linux-kernel, kernel-janitors
On Fri, Mar 01, 2024 at 06:29:52PM +0300, Dan Carpenter wrote:
> "namelen" is type size_t so it can't be negative.
>
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
Jens applied Muhammad's patch so this part isn't required any more (and
would introduce a bug if it were).
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] io_uring/net: remove unnecessary check
2024-03-01 16:56 ` Dan Carpenter
@ 2024-03-01 17:23 ` Jens Axboe
0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2024-03-01 17:23 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Pavel Begunkov, io-uring, linux-kernel, kernel-janitors
On 3/1/24 9:56 AM, Dan Carpenter wrote:
> On Fri, Mar 01, 2024 at 06:29:52PM +0300, Dan Carpenter wrote:
>> "namelen" is type size_t so it can't be negative.
>>
>> Signed-off-by: Dan Carpenter <[email protected]>
>> ---
>
> Jens applied Muhammad's patch so this part isn't required any more (and
> would introduce a bug if it were).
Yeah good point - thanks, I've dropped it.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-03-01 17:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 15:28 [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Dan Carpenter
2024-03-01 15:29 ` [PATCH 1/2] io_uring/net: fix overflow check " Dan Carpenter
2024-03-01 15:29 ` [PATCH 2/2] io_uring/net: remove unnecessary check Dan Carpenter
2024-03-01 16:56 ` Dan Carpenter
2024-03-01 17:23 ` Jens Axboe
2024-03-01 15:55 ` [PATCH 0/2] io_uring/net: fix bug in io_recvmsg_mshot_prep() Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox