Patchwork [for-1.7,v2,6/8] exec: don't ignore high address bits on set

login
register
mail settings
Submitter Marcel Apfelbaum
Date Nov. 7, 2013, 10:41 a.m.
Message ID <1383820884-29596-7-git-send-email-marcel.a@redhat.com>
Download mbox | patch
Permalink /patch/289288/
State New
Headers show

Comments

Marcel Apfelbaum - Nov. 7, 2013, 10:41 a.m.
From: "Michael S. Tsirkin" <mst@redhat.com>

We should never add pages outside target address space,
we had such bugs in the past so add debug message to catch
that quickly if we do, otherwise at least don't corrupt
the page tables.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 exec.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch

diff --git a/exec.c b/exec.c
index aeeaf00..6c3196f 100644
--- a/exec.c
+++ b/exec.c
@@ -52,6 +52,7 @@ 
 #include "exec/memory-internal.h"
 
 //#define DEBUG_SUBPAGE
+/* #define DEBUG_PHYS_PAGE_SET */
 
 #if !defined(CONFIG_USER_ONLY)
 static int in_migration;
@@ -204,6 +205,16 @@  static void phys_page_set(AddressSpaceDispatch *d,
                           hwaddr index, hwaddr nb,
                           uint16_t leaf)
 {
+    if (nb && (index + nb - 1) >= TARGET_PHYS_MAX_ADDR) {
+#ifdef DEBUG_PHYS_PAGE_SET
+        printf("%s: page table corruption: page address " TARGET_FMT_plx
+               " > max supported address %llx\n", __func__, (index + nb - 1),
+               TARGET_PHYS_MAX_ADDR);
+#endif
+        /* at least don't corrupt the page tables */
+        return;
+    }
+
     /* Wildly overreserve - it doesn't matter much. */
     phys_map_node_reserve(3 * P_L2_LEVELS);