io_uring/poll: fix signed comparison in io_poll_get_ownership()
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 io_uring/poll: fix signed comparison in io_poll_get_ownership()
From: Longxuan Yu <[email protected]>
io_poll_get_ownership() uses a signed comparison to check whether poll_refs has reached the threshold for the slowpath:
if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
atomic_read() returns int (signed). When IO_POLL_CANCEL_FLAG (BIT(31)) is set in poll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken.
Fix this by casting the atomic_read() result to unsigned int before the comparison, so that the cancel flag is treated as a large positive value and correctly triggers the slowpath.
--- io_uring/poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/poll.c +1 -1
@@ -93,7 +93,7 @@ static bool io_poll_get_ownership_slowpath(struct io_kiocb *req)*/ static inline bool io_poll_get_ownership (struct io_kiocb *req) { -if (unlikely (atomic_read (&req->poll_refs) >=IO_POLL_REF_BIAS )) +if (unlikely ((unsigned int )atomic_read (&req->poll_refs) >=IO_POLL_REF_BIAS ))return io_poll_get_ownership_slowpath (req);return !(atomic_fetch_inc (&req->poll_refs) &IO_POLL_REF_MASK ); }
Signature · 1 line
2.43.0
Quoted 7 lines · Ren Wei
From: Longxuan Yu <[email protected]>
io_poll_get_ownership()uses a signed comparison to check whetherpoll_refshas reached the threshold for the slowpath:if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
Quoted 8 lines
atomic_read()returns int (signed). WhenIO_POLL_CANCEL_FLAG(BIT(31)) is set inpoll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken.Fix this by casting the
atomic_read()result to unsigned int before the comparison, so that the cancel flag is treated as a large positive value and correctly triggers the slowpath.
Looks good, thanks for the patch
Signature · 1 line
Pavel Begunkov
Quoted 11 lines · Ren Wei
io_poll_get_ownership()uses a signed comparison to check whetherpoll_refshas reached the threshold for the slowpath:if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
atomic_read()returns int (signed). WhenIO_POLL_CANCEL_FLAG(BIT(31)) is set inpoll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken.[...]
Applied, thanks!
[1/1] io_uring/poll: fix signed comparison in io_poll_get_ownership()
commit: 326941b22806cbf2df1fbfe902b7908b368cce42
Best regards,
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 12 lines · Ren Wei
From: Longxuan Yu <[email protected]>
io_poll_get_ownership()uses a signed comparison to check whetherpoll_refshas reached the threshold for the slowpath:if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
atomic_read()returns int (signed). WhenIO_POLL_CANCEL_FLAG(BIT(31)) is set inpoll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken.
Quoted 5 lines
Fix this by casting the
atomic_read()result to unsigned int before the comparison, so that the cancel flag is treated as a large positive value and correctly triggers the slowpath.Fixes aa43477b0402 ("io_uring: poll rework")
Is this correct? Seems it should be:
Signature · 1 line
Jens Axboe
Quoted 13 lines · Jens Axboe
Quoted 12 lines · Ren Wei
From: Longxuan Yu <[email protected]>
io_poll_get_ownership()uses a signed comparison to check whetherpoll_refshas reached the threshold for the slowpath:if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
atomic_read()returns int (signed). WhenIO_POLL_CANCEL_FLAG(BIT(31)) is set inpoll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken.
Quoted 9 lines
Quoted 5 lines
Fix this by casting the
atomic_read()result to unsigned int before the comparison, so that the cancel flag is treated as a large positive value and correctly triggers the slowpath.Fixes aa43477b0402 ("io_uring: poll rework")Is this correct? Seems it should be:
Fixes a26a35e9019f ("io_uring: make poll refs more robust")
I just double check it. Yes we were wrong. Correct bug inducing commit is
a26a35e9019f ("io_uring: make poll refs more robust").
Thanks for pointing it out.
Do we need to send a v2 to fix this?
Jens Axboe
maintainerQuoted 24 lines · Yuan Tan
Quoted 13 lines · Jens Axboe
Quoted 12 lines · Ren Wei
From: Longxuan Yu <[email protected]>
io_poll_get_ownership()uses a signed comparison to check whetherpoll_refshas reached the threshold for the slowpath:if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
atomic_read()returns int (signed). WhenIO_POLL_CANCEL_FLAG(BIT(31)) is set inpoll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken.Quoted 9 lines
Quoted 5 lines
Fix this by casting the
atomic_read()result to unsigned int before the comparison, so that the cancel flag is treated as a large positive value and correctly triggers the slowpath.Fixes aa43477b0402 ("io_uring: poll rework")Is this correct? Seems it should be:
Fixes a26a35e9019f ("io_uring: make poll refs more robust")
Quoted 8 lines
I just double check it. Yes we were wrong. Correct bug inducing commit is
a26a35e9019f("io_uring: make poll refs more robust").Thanks for pointing it out.
Do we need to send a v2 to fix this?
No need, I corrected it already while applying yesterday.
Signature · 1 line
Jens Axboe