render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
a41c76
From 57eb21eb48d76798f0c990c839df148301e9cb0e Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <57eb21eb48d76798f0c990c839df148301e9cb0e@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Wed, 19 Feb 2020 15:10:10 +0100
a41c76
Subject: [PATCH] virStorageSourceParseBackingJSON: Prevent arbitrary nesting
a41c76
 with format drivers
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Since we parse attributes for 'raw' which is a format driver and thus
a41c76
has nested 'file' structure we must prevent that this isn't nested
a41c76
arbitrarily.
a41c76
a41c76
Add a flag for the function which allows parsing of 'format' type
a41c76
drivers only on the first pass.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit fd70f1b4d324361bb9a708762631690aca043178)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1791788
a41c76
Message-Id: <b5ed395d736eb8570467e2eafb44288d77d416e7.1582120424.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/util/virstoragefile.c | 23 +++++++++++++++++------
a41c76
 1 file changed, 17 insertions(+), 6 deletions(-)
a41c76
a41c76
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
a41c76
index dd05de188f..b02fad92b6 100644
a41c76
--- a/src/util/virstoragefile.c
a41c76
+++ b/src/util/virstoragefile.c
a41c76
@@ -3052,7 +3052,8 @@ virStorageSourceParseBackingColon(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
a41c76
                                          virJSONValuePtr json,
a41c76
-                                         const char *jsonstr);
a41c76
+                                         const char *jsonstr,
a41c76
+                                         bool allowformat);
a41c76
 
a41c76
 
a41c76
 static int
a41c76
@@ -3531,7 +3532,7 @@ virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src,
a41c76
         return -1;
a41c76
     }
a41c76
 
a41c76
-    return virStorageSourceParseBackingJSONInternal(src, file, jsonstr);
a41c76
+    return virStorageSourceParseBackingJSONInternal(src, file, jsonstr, false);
a41c76
 }
a41c76
 
a41c76
 
a41c76
@@ -3606,7 +3607,8 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
a41c76
                                          virJSONValuePtr json,
a41c76
-                                         const char *jsonstr)
a41c76
+                                         const char *jsonstr,
a41c76
+                                         bool allowformat)
a41c76
 {
a41c76
     const char *drvname;
a41c76
     size_t i;
a41c76
@@ -3619,8 +3621,17 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
a41c76
     }
a41c76
 
a41c76
     for (i = 0; i < G_N_ELEMENTS(jsonParsers); i++) {
a41c76
-        if (STREQ(drvname, jsonParsers[i].drvname))
a41c76
-            return jsonParsers[i].func(src, json, jsonstr, jsonParsers[i].opaque);
a41c76
+        if (STRNEQ(drvname, jsonParsers[i].drvname))
a41c76
+            continue;
a41c76
+
a41c76
+        if (jsonParsers[i].formatdriver && !allowformat) {
a41c76
+            virReportError(VIR_ERR_INVALID_ARG,
a41c76
+                           _("JSON backing volume definition '%s' must not have nested format drivers"),
a41c76
+                           jsonstr);
a41c76
+            return -1;
a41c76
+        }
a41c76
+
a41c76
+        return jsonParsers[i].func(src, json, jsonstr, jsonParsers[i].opaque);
a41c76
     }
a41c76
 
a41c76
     virReportError(VIR_ERR_INTERNAL_ERROR,
a41c76
@@ -3655,7 +3666,7 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
a41c76
     if (!file)
a41c76
         file = deflattened;
a41c76
 
a41c76
-    return virStorageSourceParseBackingJSONInternal(src, file, json);
a41c76
+    return virStorageSourceParseBackingJSONInternal(src, file, json, true);
a41c76
 }
a41c76
 
a41c76
 
a41c76
-- 
a41c76
2.25.0
a41c76