c1c534
From e3521dc836329e941d3d7bea0bcac1b0731162a5 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <e3521dc836329e941d3d7bea0bcac1b0731162a5@dist-git>
c1c534
From: Martin Kletzander <mkletzan@redhat.com>
c1c534
Date: Mon, 5 Feb 2018 13:39:19 +0100
c1c534
Subject: [PATCH] util: Check if kernel-provided info is consistent with itself
c1c534
c1c534
Just in case someone re-mounted /sys/fs/resctrl with different mount
c1c534
options (cdp), add a check here.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1540780
c1c534
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
(cherry picked from commit d300b5448721970962efc18c3b3b0a358f2359ab)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
---
c1c534
 src/util/virresctrl.c | 11 +++++++++++
c1c534
 1 file changed, 11 insertions(+)
c1c534
c1c534
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
c1c534
index ef388757a7..6860e86e64 100644
c1c534
--- a/src/util/virresctrl.c
c1c534
+++ b/src/util/virresctrl.c
c1c534
@@ -941,6 +941,17 @@ virResctrlAllocParseProcessCache(virResctrlInfoPtr resctrl,
c1c534
     if (!mask)
c1c534
         return -1;
c1c534
 
c1c534
+    if (!resctrl ||
c1c534
+        level >= resctrl->nlevels ||
c1c534
+        !resctrl->levels[level] ||
c1c534
+        !resctrl->levels[level]->types[type]) {
c1c534
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c1c534
+                       _("Missing or inconsistent resctrl info for "
c1c534
+                         "level '%ud' type '%s'"),
c1c534
+                       level, virCacheTypeToString(type));
c1c534
+        goto cleanup;
c1c534
+    }
c1c534
+
c1c534
     if (virBitmapShrink(mask, resctrl->levels[level]->types[type]->bits) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
-- 
c1c534
2.16.1
c1c534