aio-win32: avoid out-of-bounds access to the events array
PATCH 1/1 aio-win32: avoid out-of-bounds access to the events array
If ret is WAIT_TIMEOUT and there was an event returned by select(), we can write to a location after the end of the array. But in that case we can retry the WaitForMultipleObjects call with the same set of events, so just move the event[ret - WAIT_OBJECT_0] assignment inside the existin conditional.
--- aio-win32.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
aio-win32.c +1 -3
@@ -335,6 +335,7 @@ bool aio_poll(AioContext *ctx, bool blocking) event =NULL ;if ((DWORD ) (ret -WAIT_OBJECT_0 ) < count) { event = events[ret -WAIT_OBJECT_0 ]; + events[ret -WAIT_OBJECT_0 ] = events[--count]; }else if (!have_select_revents) {break ; }
@@ -343,9 +344,6 @@ bool aio_poll(AioContext *ctx, bool blocking) blocking = false; progress |=aio_dispatch_handlers (ctx, event); - -/* Try again, but only call each handler once. */ - events[ret -WAIT_OBJECT_0 ] = events[--count]; } progress |=timerlistgroup_run_timers (&ctx->tlg);
Signature · 1 line
2.1.0
Quoted 35 lines · Paolo Bonzini
If ret is
WAIT_TIMEOUTand there was an event returned byselect(), we can write to a location after the end of the array. But in that case we can retry the WaitForMultipleObjects call with the same set of events, so just move the event[ret -WAIT_OBJECT_0] assignment inside the existin conditional.Reported-by TeLeMan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- aio-win32.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)aio-win32.c +1
-4@@ -335,6 +335,7 @@ bool aio_poll(AioContext *ctx, bool blocking) event =NULL ;if ((DWORD ) (ret -WAIT_OBJECT_0 ) < count) { event = events[ret -WAIT_OBJECT_0 ]; + events[ret -WAIT_OBJECT_0 ] = events[--count]; }else if (!have_select_revents) {break ; }@@ -343,9 +344,6 @@ bool aio_poll(AioContext *ctx, bool blocking) blocking = false; progress |=aio_dispatch_handlers (ctx, event); - -/* Try again, but only call each handler once. */ - events[ret -WAIT_OBJECT_0 ] = events[--count]; } progress |=timerlistgroup_run_timers (&ctx->tlg); --
Quoted 2 lines
2.1.0
Stefan Hajnoczi
AppliedQuoted 11 lines · Paolo Bonzini
If ret is
WAIT_TIMEOUTand there was an event returned byselect(), we can write to a location after the end of the array. But in that case we can retry the WaitForMultipleObjects call with the same set of events, so just move the event[ret -WAIT_OBJECT_0] assignment inside the existin conditional.Reported-by TeLeMan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- aio-win32.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan