Blame SOURCES/libvirt-Add-bounds-checking-on-virDomain-SnapshotListAllChildren-ListAllSnapshots-RPC-calls.patch

43fe83
From c0d1584975c670974915498f02da48887f26fb9e Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <c0d1584975c670974915498f02da48887f26fb9e.1377873639.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Fri, 30 Aug 2013 11:16:05 +0100
43fe83
Subject: [PATCH] Add bounds checking on virDomain{SnapshotListAllChildren,
43fe83
 ListAllSnapshots} RPC calls
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=1002667
43fe83
43fe83
The return values for the virDomain{SnapshotListAllChildren,ListAllSnapshots}
43fe83
calls were not 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 a43d4f543c31a17ab3a29ad8e01828ff30390622)
43fe83
---
43fe83
 daemon/remote.c              | 14 ++++++++++++++
43fe83
 src/remote/remote_driver.c   | 16 ++++++++++++++++
43fe83
 src/remote/remote_protocol.x | 10 +++++-----
43fe83
 3 files changed, 35 insertions(+), 5 deletions(-)
43fe83
43fe83
diff --git a/daemon/remote.c b/daemon/remote.c
43fe83
index ad78011..e228cba 100644
43fe83
--- a/daemon/remote.c
43fe83
+++ b/daemon/remote.c
43fe83
@@ -3934,6 +3934,13 @@ remoteDispatchDomainListAllSnapshots(virNetServerPtr server ATTRIBUTE_UNUSED,
43fe83
                                             args->flags)) < 0)
43fe83
         goto cleanup;
43fe83
 
43fe83
+    if (nsnaps > REMOTE_DOMAIN_SNAPSHOT_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many domain snapshots '%d' for limit '%d'"),
43fe83
+                       nsnaps, REMOTE_DOMAIN_SNAPSHOT_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (snaps && nsnaps) {
43fe83
         if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0)
43fe83
             goto cleanup;
43fe83
@@ -3996,6 +4003,13 @@ remoteDispatchDomainSnapshotListAllChildren(virNetServerPtr server ATTRIBUTE_UNU
43fe83
                                                    args->flags)) < 0)
43fe83
         goto cleanup;
43fe83
 
43fe83
+    if (nsnaps > REMOTE_DOMAIN_SNAPSHOT_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many domain snapshots '%d' for limit '%d'"),
43fe83
+                       nsnaps, REMOTE_DOMAIN_SNAPSHOT_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (snaps && nsnaps) {
43fe83
         if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0)
43fe83
             goto cleanup;
43fe83
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
43fe83
index 33b2b0f..14c16f6 100644
43fe83
--- a/src/remote/remote_driver.c
43fe83
+++ b/src/remote/remote_driver.c
43fe83
@@ -5760,6 +5760,14 @@ remoteDomainListAllSnapshots(virDomainPtr dom,
43fe83
              (char *) &ret) == -1)
43fe83
         goto done;
43fe83
 
43fe83
+    if (ret.snapshots.snapshots_len > REMOTE_DOMAIN_SNAPSHOT_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many domain snapshots '%d' for limit '%d'"),
43fe83
+                       ret.snapshots.snapshots_len,
43fe83
+                       REMOTE_DOMAIN_SNAPSHOT_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (snapshots) {
43fe83
         if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0)
43fe83
             goto cleanup;
43fe83
@@ -5819,6 +5827,14 @@ remoteDomainSnapshotListAllChildren(virDomainSnapshotPtr parent,
43fe83
              (char *) &ret) == -1)
43fe83
         goto done;
43fe83
 
43fe83
+    if (ret.snapshots.snapshots_len > REMOTE_DOMAIN_SNAPSHOT_LIST_MAX) {
43fe83
+        virReportError(VIR_ERR_RPC,
43fe83
+                       _("Too many domain snapshots '%d' for limit '%d'"),
43fe83
+                       ret.snapshots.snapshots_len,
43fe83
+                       REMOTE_DOMAIN_SNAPSHOT_LIST_MAX);
43fe83
+        goto cleanup;
43fe83
+    }
43fe83
+
43fe83
     if (snapshots) {
43fe83
         if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0)
43fe83
             goto cleanup;
43fe83
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
43fe83
index eff7e1c..9e3918c 100644
43fe83
--- a/src/remote/remote_protocol.x
43fe83
+++ b/src/remote/remote_protocol.x
43fe83
@@ -154,7 +154,7 @@ const REMOTE_AUTH_TYPE_LIST_MAX = 20;
43fe83
 const REMOTE_DOMAIN_MEMORY_STATS_MAX = 1024;
43fe83
 
43fe83
 /* Upper limit on lists of domain snapshots. */
43fe83
-const REMOTE_DOMAIN_SNAPSHOT_LIST_NAMES_MAX = 1024;
43fe83
+const REMOTE_DOMAIN_SNAPSHOT_LIST_MAX = 1024;
43fe83
 
43fe83
 /* Maximum length of a block peek buffer message.
43fe83
  * Note applications need to be aware of this limit and issue multiple
43fe83
@@ -2396,7 +2396,7 @@ struct remote_domain_snapshot_list_names_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_domain_snapshot_list_names_ret {
43fe83
-    remote_nonnull_string names<REMOTE_DOMAIN_SNAPSHOT_LIST_NAMES_MAX>; /* insert@1 */
43fe83
+    remote_nonnull_string names<REMOTE_DOMAIN_SNAPSHOT_LIST_MAX>; /* insert@1 */
43fe83
 };
43fe83
 
43fe83
 struct remote_domain_list_all_snapshots_args {
43fe83
@@ -2406,7 +2406,7 @@ struct remote_domain_list_all_snapshots_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_domain_list_all_snapshots_ret {
43fe83
-    remote_nonnull_domain_snapshot snapshots<>;
43fe83
+    remote_nonnull_domain_snapshot snapshots<REMOTE_DOMAIN_SNAPSHOT_LIST_MAX>;
43fe83
     int ret;
43fe83
 };
43fe83
 
43fe83
@@ -2426,7 +2426,7 @@ struct remote_domain_snapshot_list_children_names_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_domain_snapshot_list_children_names_ret {
43fe83
-    remote_nonnull_string names<REMOTE_DOMAIN_SNAPSHOT_LIST_NAMES_MAX>; /* insert@1 */
43fe83
+    remote_nonnull_string names<REMOTE_DOMAIN_SNAPSHOT_LIST_MAX>; /* insert@1 */
43fe83
 };
43fe83
 
43fe83
 struct remote_domain_snapshot_list_all_children_args {
43fe83
@@ -2436,7 +2436,7 @@ struct remote_domain_snapshot_list_all_children_args {
43fe83
 };
43fe83
 
43fe83
 struct remote_domain_snapshot_list_all_children_ret {
43fe83
-    remote_nonnull_domain_snapshot snapshots<>;
43fe83
+    remote_nonnull_domain_snapshot snapshots<REMOTE_DOMAIN_SNAPSHOT_LIST_MAX>;
43fe83
     int ret;
43fe83
 };
43fe83
 
43fe83
-- 
43fe83
1.8.3.2
43fe83