43fe83
From c492435723a14ee2fa5991228c98a791ad68c7ac Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <c492435723a14ee2fa5991228c98a791ad68c7ac.1377873640.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Fri, 30 Aug 2013 11:16:09 +0100
43fe83
Subject: [PATCH] Add bounds checking on virConnectListAllNetworks RPC call
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=1002667
43fe83
43fe83
The return values for the virConnectListAllNetworks 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 174f7dd5bafb1a6d8e341078149855cd2d790082)
43fe83
---
43fe83
 daemon/remote.c              |  7 +++++++
43fe83
 src/remote/remote_driver.c   |  7 +++++++
43fe83
 src/remote/remote_protocol.x | 10 +++++-----
43fe83
 3 files changed, 19 insertions(+), 5 deletions(-)
43fe83
43fe83
diff --git a/daemon/remote.c b/daemon/remote.c
43fe83
index 512170b..b6501e0 100644
43fe83
--- a/daemon/remote.c
43fe83
+++ b/daemon/remote.c
43fe83
@@ -4197,6 +4197,13 @@ remoteDispatchConnectListAllNetworks(virNetServerPtr server ATTRIBUTE_UNUSED,
43fe83
                                            args->flags)) < 0)
43fe83
         goto cleanup;
43fe83
 
43fe83
+    if (nnets > REMOTE_NETWORK_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many networks '%d' for limit '%d'"),
43fe83
+                       nnets, REMOTE_NETWORK_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (nets && nnets) {
43fe83
         if (VIR_ALLOC_N(ret->nets.nets_val, nnets) < 0)
43fe83
             goto cleanup;
43fe83
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
43fe83
index 542cb39..e555704 100644
43fe83
--- a/src/remote/remote_driver.c
43fe83
+++ b/src/remote/remote_driver.c
43fe83
@@ -2843,6 +2843,13 @@ remoteConnectListAllNetworks(virConnectPtr conn,
43fe83
              (char *) &ret) == -1)
43fe83
         goto done;
43fe83
 
43fe83
+    if (ret.nets.nets_len > REMOTE_NETWORK_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many networks '%d' for limit '%d'"),
43fe83
+                       ret.nets.nets_len, REMOTE_NETWORK_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (nets) {
43fe83
         if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0)
43fe83
             goto cleanup;
43fe83
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
43fe83
index 2034aa1..f1e27fa 100644
43fe83
--- a/src/remote/remote_protocol.x
43fe83
+++ b/src/remote/remote_protocol.x
43fe83
@@ -88,8 +88,8 @@ const REMOTE_CPUMAPS_MAX = 8388608;
43fe83
 /* Upper limit on migrate cookie. */
43fe83
 const REMOTE_MIGRATE_COOKIE_MAX = 16384;
43fe83
 
43fe83
-/* Upper limit on lists of network names. */
43fe83
-const REMOTE_NETWORK_NAME_LIST_MAX = 16384;
43fe83
+/* Upper limit on lists of networks. */
43fe83
+const REMOTE_NETWORK_LIST_MAX = 16384;
43fe83
 
43fe83
 /* Upper limit on lists of interface names. */
43fe83
 const REMOTE_INTERFACE_NAME_LIST_MAX = 16384;
43fe83
@@ -1317,7 +1317,7 @@ struct remote_connect_list_networks_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_list_networks_ret {
43fe83
-    remote_nonnull_string names<REMOTE_NETWORK_NAME_LIST_MAX>; /* insert@1 */
43fe83
+    remote_nonnull_string names<REMOTE_NETWORK_LIST_MAX>; /* insert@1 */
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_num_of_defined_networks_ret {
43fe83
@@ -1329,7 +1329,7 @@ struct remote_connect_list_defined_networks_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_list_defined_networks_ret {
43fe83
-    remote_nonnull_string names<REMOTE_NETWORK_NAME_LIST_MAX>; /* insert@1 */
43fe83
+    remote_nonnull_string names<REMOTE_NETWORK_LIST_MAX>; /* insert@1 */
43fe83
 };
43fe83
 
43fe83
 struct remote_network_lookup_by_uuid_args {
43fe83
@@ -2691,7 +2691,7 @@ struct remote_connect_list_all_networks_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_connect_list_all_networks_ret {
43fe83
-    remote_nonnull_network nets<>;
43fe83
+    remote_nonnull_network nets<REMOTE_NETWORK_LIST_MAX>;
43fe83
     unsigned int ret;
43fe83
 };
43fe83
 
43fe83
-- 
43fe83
1.8.3.2
43fe83