From 6040b8ad9a04434782f7cd037db33768456e151a Mon Sep 17 00:00:00 2001 Message-Id: <6040b8ad9a04434782f7cd037db33768456e151a.1377873640.git.jdenemar@redhat.com> From: "Daniel P. Berrange" Date: Fri, 30 Aug 2013 11:16:13 +0100 Subject: [PATCH] Add bounds checking on virConnectListAllSecrets RPC call For https://bugzilla.redhat.com/show_bug.cgi?id=1002667 The return values for the virConnectListAllSecrets call were not bounds checked. This is a robustness issue for clients if something where to cause corruption of the RPC stream data. Signed-off-by: Daniel P. Berrange (cherry picked from commit 47fb5672f2f4e9efcd4e9ec30f5e723c46fa8e6f) --- daemon/remote.c | 7 +++++++ src/remote/remote_driver.c | 7 +++++++ src/remote/remote_protocol.x | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index e19b42d..6ace7af 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -4433,6 +4433,13 @@ remoteDispatchConnectListAllSecrets(virNetServerPtr server ATTRIBUTE_UNUSED, args->flags)) < 0) goto cleanup; + if (nsecrets > REMOTE_SECRET_LIST_MAX) { + virReportError(VIR_ERR_RPC, + _("Too many secrets '%d' for limit '%d'"), + nsecrets, REMOTE_SECRET_LIST_MAX); + goto cleanup; + } + if (secrets && nsecrets) { if (VIR_ALLOC_N(ret->secrets.secrets_val, nsecrets) < 0) goto cleanup; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d486fa5..62e77a5 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3107,6 +3107,13 @@ remoteConnectListAllSecrets(virConnectPtr conn, (char *) &ret) == -1) goto done; + if (ret.secrets.secrets_len > REMOTE_SECRET_LIST_MAX) { + virReportError(VIR_ERR_RPC, + _("Too many secrets '%d' for limit '%d'"), + ret.secrets.secrets_len, REMOTE_SECRET_LIST_MAX); + goto cleanup; + } + if (secrets) { if (VIR_ALLOC_N(tmp_secrets, ret.secrets.secrets_len + 1) < 0) goto cleanup; diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index b2841a7..a1c23da 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -188,7 +188,7 @@ const REMOTE_SECRET_VALUE_MAX = 65536; /* * Upper limit on list of secrets. */ -const REMOTE_SECRET_UUID_LIST_MAX = 16384; +const REMOTE_SECRET_LIST_MAX = 16384; /* * Upper limit on list of CPUs accepted when computing a baseline CPU. @@ -2002,7 +2002,7 @@ struct remote_connect_list_secrets_args { }; struct remote_connect_list_secrets_ret { - remote_nonnull_string uuids; /* insert@1 */ + remote_nonnull_string uuids; /* insert@1 */ }; struct remote_secret_lookup_by_uuid_args { @@ -2728,7 +2728,7 @@ struct remote_connect_list_all_secrets_args { }; struct remote_connect_list_all_secrets_ret { - remote_nonnull_secret secrets<>; + remote_nonnull_secret secrets; unsigned int ret; }; -- 1.8.3.2