nbd: avoid out of bounds access to recv_coroutine array
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 12 Mar 2012 14:23:13 +0000 (15:23 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 19 Apr 2012 14:36:42 +0000 (16:36 +0200)
This can happen with a buggy or malicious server.

Reported-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block/nbd.c

index 161b299855c3b817b3d41d13091547aa934c9cbd..9972cdb6551c2af20e2844fc8826aa0f57b1912b 100644 (file)
@@ -150,7 +150,7 @@ static int nbd_have_request(void *opaque)
 static void nbd_reply_ready(void *opaque)
 {
     BDRVNBDState *s = opaque;
-    int i;
+    uint64_t i;
 
     if (s->reply.handle == 0) {
         /* No reply already in flight.  Fetch a header.  */
@@ -164,6 +164,10 @@ static void nbd_reply_ready(void *opaque)
      * handler acts as a synchronization point and ensures that only
      * one coroutine is called until the reply finishes.  */
     i = HANDLE_TO_INDEX(s, s->reply.handle);
+    if (i >= MAX_NBD_REQUESTS) {
+        goto fail;
+    }
+
     if (s->recv_coroutine[i]) {
         qemu_coroutine_enter(s->recv_coroutine[i], NULL);
         return;