43fe83
From f79b8cfc288deb39dc652a7a552f8bcb85dc1148 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <f79b8cfc288deb39dc652a7a552f8bcb85dc1148.1377873639.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Fri, 30 Aug 2013 11:16:06 +0100
43fe83
Subject: [PATCH] Add bounds checking on virConnectListAllDomains RPC call
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=1002667
43fe83
43fe83
The return values for the virConnectListAllDomains call were not
43fe83
bounds checked. This is a robustness issue for clients if
43fe83
something where to cause corruption of the RPC stream data.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit 9e97128ba5a1045b71b50adb23993f09628f0a24)
43fe83
---
43fe83
 daemon/remote.c              |  7 +++++++
43fe83
 src/remote/remote_driver.c   | 15 +++++++++++----
43fe83
 src/remote/remote_protocol.x | 15 +++++----------
43fe83
 3 files changed, 23 insertions(+), 14 deletions(-)
43fe83
43fe83
diff --git a/daemon/remote.c b/daemon/remote.c
43fe83
index e228cba..8289cb5 100644
43fe83
--- a/daemon/remote.c
43fe83
+++ b/daemon/remote.c
43fe83
@@ -1050,6 +1050,13 @@ remoteDispatchConnectListAllDomains(virNetServerPtr server ATTRIBUTE_UNUSED,
43fe83
                                              args->flags)) < 0)
43fe83
         goto cleanup;
43fe83
 
43fe83
+    if (ndomains > REMOTE_DOMAIN_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many domains '%d' for limit '%d'"),
43fe83
+                       ndomains, REMOTE_DOMAIN_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (doms && ndomains) {
43fe83
         if (VIR_ALLOC_N(ret->domains.domains_val, ndomains) < 0)
43fe83
             goto cleanup;
43fe83
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
43fe83
index 14c16f6..cd2b9a9 100644
43fe83
--- a/src/remote/remote_driver.c
43fe83
+++ b/src/remote/remote_driver.c
43fe83
@@ -1370,10 +1370,10 @@ remoteConnectListDomains(virConnectPtr conn, int *ids, int maxids)
43fe83
 
43fe83
     remoteDriverLock(priv);
43fe83
 
43fe83
-    if (maxids > REMOTE_DOMAIN_ID_LIST_MAX) {
43fe83
+    if (maxids > REMOTE_DOMAIN_LIST_MAX) {
43fe83
         virReportError(VIR_ERR_RPC,
43fe83
-                       _("too many remote domain IDs: %d > %d"),
43fe83
-                       maxids, REMOTE_DOMAIN_ID_LIST_MAX);
43fe83
+                       _("Too many domains '%d' for limit '%d'"),
43fe83
+                       maxids, REMOTE_DOMAIN_LIST_MAX);
43fe83
         goto done;
43fe83
     }
43fe83
     args.maxids = maxids;
43fe83
@@ -1386,7 +1386,7 @@ remoteConnectListDomains(virConnectPtr conn, int *ids, int maxids)
43fe83
 
43fe83
     if (ret.ids.ids_len > maxids) {
43fe83
         virReportError(VIR_ERR_RPC,
43fe83
-                       _("too many remote domain IDs: %d > %d"),
43fe83
+                       _("Too many domains '%d' for limit '%d'"),
43fe83
                        ret.ids.ids_len, maxids);
43fe83
         goto cleanup;
43fe83
     }
43fe83
@@ -1433,6 +1433,13 @@ remoteConnectListAllDomains(virConnectPtr conn,
43fe83
              (char *) &ret) == -1)
43fe83
         goto done;
43fe83
 
43fe83
+    if (ret.domains.domains_len > REMOTE_DOMAIN_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many domains '%d' for limit '%d'"),
43fe83
+                       ret.domains.domains_len, REMOTE_DOMAIN_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (domains) {
43fe83
         if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0)
43fe83
             goto cleanup;
43fe83
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
43fe83
index 9e3918c..718e398 100644
43fe83
--- a/src/remote/remote_protocol.x
43fe83
+++ b/src/remote/remote_protocol.x
43fe83
@@ -73,13 +73,8 @@ typedef string remote_nonnull_string<REMOTE_STRING_MAX>;
43fe83
 /* A long string, which may be NULL. */
43fe83
 typedef remote_nonnull_string *remote_string;
43fe83
 
43fe83
-/* This just places an upper limit on the length of lists of
43fe83
- * domain IDs which may be sent via the protocol.
43fe83
- */
43fe83
-const REMOTE_DOMAIN_ID_LIST_MAX = 16384;
43fe83
-
43fe83
-/* Upper limit on lists of domain names. */
43fe83
-const REMOTE_DOMAIN_NAME_LIST_MAX = 16384;
43fe83
+/* Upper limit on lists of domains. */
43fe83
+const REMOTE_DOMAIN_LIST_MAX = 16384;
43fe83
 
43fe83
 /* Upper limit on cpumap (bytes) passed to virDomainPinVcpu. */
43fe83
 const REMOTE_CPUMAP_MAX = 2048;
43fe83
@@ -724,7 +719,7 @@ struct remote_connect_list_domains_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_list_domains_ret {
43fe83
-    int ids<REMOTE_DOMAIN_ID_LIST_MAX>; /* insert@1 */
43fe83
+    int ids<REMOTE_DOMAIN_LIST_MAX>; /* insert@1 */
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_num_of_domains_ret {
43fe83
@@ -990,7 +985,7 @@ struct remote_connect_list_defined_domains_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_list_defined_domains_ret {
43fe83
-    remote_nonnull_string names<REMOTE_DOMAIN_NAME_LIST_MAX>; /* insert@1 */
43fe83
+    remote_nonnull_string names<REMOTE_DOMAIN_LIST_MAX>; /* insert@1 */
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_num_of_defined_domains_ret {
43fe83
@@ -2665,7 +2660,7 @@ struct remote_connect_list_all_domains_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_list_all_domains_ret {
43fe83
-    remote_nonnull_domain domains<>;
43fe83
+    remote_nonnull_domain domains<REMOTE_DOMAIN_LIST_MAX>;
43fe83
     unsigned int ret;
43fe83
 };
43fe83
 
43fe83
-- 
43fe83
1.8.3.2
43fe83