Skip to contentSkip to conversation

migration: fix potential overflow in multifd send

PATCH In review Peter Xu 4 participants 4 messages Jul 20, 2018 – Jul 24, 2018

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 migration: fix potential overflow in multifd send

I would guess it won't happen normally, but this should ease Coverity.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1394385: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
Potentially overflowing expression "pages->used * 8192U" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).

854 transferred = pages->used * TARGET_PAGE_SIZE + p->packet_len;

Fixes CID 1394385
CC Juan Quintela <[email protected]>
---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index 52dd678092..fdd108475c 100644
@@ -851,7 +851,7 @@ static void multifd_send_pages(void)
     p->pages->block = NULL;
     multifd_send_state->pages = p->pages;
     p->pages = pages;
-    transferred = pages->used * TARGET_PAGE_SIZE + p->packet_len;
+    transferred = ((uint64_t) pages->used) * TARGET_PAGE_SIZE + p->packet_len;
     ram_counters.multifd_bytes += transferred;
     ram_counters.transferred += transferred;;
     qemu_mutex_unlock(&p->mutex);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Peter Xu

I would guess it won't happen normally, but this should ease Coverity.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

CID 1394385: Integer handling issues (OVERFLOW_BEFORE_WIDEN) Potentially overflowing expression "pages->used * 8192U" with
type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).

Quoted 5 lines

854 transferred = pages->used * TARGET_PAGE_SIZE + p->packet_len;

Fixes CID 1394385
CC Juan Quintela <[email protected]>

a - I hate C promotion rules
b - why gcc don't warn me
c - it don't matter. If the size of the package is bigger than 4GB, we
have other problems already.

Thanks, Juan.

#2 lore raw
In reply to Peter Xu
Quoted 9 lines · * Peter Xu ([email protected]) wrote:

I would guess it won't happen normally, but this should ease Coverity.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1394385: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
Potentially overflowing expression "pages->used * 8192U" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).

854 transferred = pages->used * TARGET_PAGE_SIZE + p->packet_len;

Fixes CID 1394385
CC Juan Quintela <[email protected]>

Queued

Quoted 21 lines
---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/ram.c +1 -1
index 52dd678092..fdd108475c 100644
@@ -851,7 +851,7 @@ static void multifd_send_pages(void)
     p->pages->block = NULL;
     multifd_send_state->pages = p->pages;
     p->pages = pages;
-    transferred = pages->used * TARGET_PAGE_SIZE + p->packet_len;
+    transferred = ((uint64_t) pages->used) * TARGET_PAGE_SIZE + p->packet_len;
     ram_counters.multifd_bytes += transferred;
     ram_counters.transferred += transferred;;
     qemu_mutex_unlock(&p->mutex);
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
Quoted 11 lines · Dr. David Alan Gilbert

migration/ram.c static void multifd_send_pages(void) · line 854

Quoted 10 lines · * Peter Xu ([email protected]) wrote:

I would guess it won't happen normally, but this should ease Coverity.

+++ b/migration/ram.c

migration/ram.c +1 -1
@@ -851,7 +851,7 @@ static void multifd_send_pages(void)
      p->pages->block = NULL;
      multifd_send_state->pages = p->pages;
      p->pages = pages;
-    transferred = pages->used * TARGET_PAGE_SIZE + p->packet_len;
+    transferred = ((uint64_t) pages->used) * TARGET_PAGE_SIZE + p->packet_len;

The outer () are not strictly necessary, as casts bind tighter than multiply.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org