]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
remote: protect against integer overflow
authorEric Blake <eblake@redhat.com>
Fri, 24 Jun 2011 18:16:05 +0000 (12:16 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 24 Jun 2011 21:57:23 +0000 (15:57 -0600)
Integer overflow and remote code are never a nice mix.

This has existed since commit 56cd414.

* src/libvirt.c (virDomainGetVcpus): Reject overflow up front.
* src/remote/remote_driver.c (remoteDomainGetVcpus): Avoid overflow
on sending rpc.
* daemon/remote.c (remoteDispatchDomainGetVcpus): Avoid overflow on
receiving rpc.

daemon/remote.c
src/libvirt.c
src/remote/remote_driver.c

index 48624d6902ebbfbdc9159c346eb100a5941a89f1..8d04fc7dfb646240dea19a29e52080df1dd9d4ef 100644 (file)
@@ -61,6 +61,7 @@
 #include "network.h"
 #include "libvirt/libvirt-qemu.h"
 #include "command.h"
+#include "intprops.h"
 
 #define VIR_FROM_THIS VIR_FROM_REMOTE
 
@@ -1074,7 +1075,8 @@ remoteDispatchDomainGetVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
         goto cleanup;
     }
 
-    if (args->maxinfo * args->maplen > REMOTE_CPUMAPS_MAX) {
+    if (INT_MULTIPLY_OVERFLOW(args->maxinfo, args->maplen) ||
+        args->maxinfo * args->maplen > REMOTE_CPUMAPS_MAX) {
         virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen > REMOTE_CPUMAPS_MAX"));
         goto cleanup;
     }
index 76e16ad49a7925f720921c81ccc915fbc312e920..9fe9a6924e3845c2fa32f611eb4f6afa2c9e542d 100644 (file)
@@ -39,6 +39,7 @@
 #include "util.h"
 #include "memory.h"
 #include "configmake.h"
+#include "intprops.h"
 
 #ifndef WITH_DRIVER_MODULES
 # ifdef WITH_TEST
@@ -7153,8 +7154,8 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
 
     /* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not
        try to memcpy anything into a NULL pointer.  */
-    if ((cpumaps == NULL && maplen != 0)
-        || (cpumaps && maplen <= 0)) {
+    if (!cpumaps ? maplen != 0
+        : (maplen <= 0 || INT_MULTIPLY_OVERFLOW(maxinfo, maplen))) {
         virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         goto error;
     }
index a7ac90a69853aa47a1b6f28f471a9c5ef9434f30..f2edf436bbda3dc22c5efa68a3a5908bbec5684d 100644 (file)
@@ -83,6 +83,7 @@
 #include "ignore-value.h"
 #include "files.h"
 #include "command.h"
+#include "intprops.h"
 
 #define VIR_FROM_THIS VIR_FROM_REMOTE
 
@@ -2161,7 +2162,8 @@ remoteDomainGetVcpus (virDomainPtr domain,
                     maxinfo, REMOTE_VCPUINFO_MAX);
         goto done;
     }
-    if (maxinfo * maplen > REMOTE_CPUMAPS_MAX) {
+    if (INT_MULTIPLY_OVERFLOW(maxinfo, maplen) ||
+        maxinfo * maplen > REMOTE_CPUMAPS_MAX) {
         remoteError(VIR_ERR_RPC,
                     _("vCPU map buffer length exceeds maximum: %d > %d"),
                     maxinfo * maplen, REMOTE_CPUMAPS_MAX);