Skip to contentSkip to conversation

xen: arm: do not BUG on guest paddrs which are very high

PATCH Superseded Ian Campbell 2 participants 3 messages Dec 5, 2013 – Dec 6, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: arm: do not BUG on guest paddrs which are very high

The BUG_ON in p2m_map_first was over aggressive since the paddr_t can have come from the guest, via add_to_physmap. Instead return failure to the caller.

Also the check was simultaneously too lose. The valid offsets are 0..P2M_FIRST_ENTRIES-1 inclusive.

---
 xen/arch/arm/p2m.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
xen/arch/arm/p2m.c +9 -1
index 1d5c841..cd134d4 100644
@@ -58,7 +58,8 @@ static lpae_t *p2m_map_first(struct p2m_domain *p2m, paddr_t addr)
 {
     struct page_info *page;
 
-    BUG_ON(first_linear_offset(addr) > P2M_FIRST_ENTRIES);
+    if ( first_linear_offset(addr) >= P2M_FIRST_ENTRIES )
+        return NULL;
 
     page = p2m->first_level + p2m_first_level_index(addr);
 
@@ -80,6 +81,8 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr)
     spin_lock(&p2m->lock);
 
     first = p2m_map_first(p2m, paddr);
+    if ( !first )
+        goto done;
 
     pte = first[first_table_offset(paddr)];
     if ( !pte.p2m.valid || !pte.p2m.table )
@@ -181,6 +184,11 @@ static int create_p2m_entries(struct domain *d,
         {
             if ( first ) unmap_domain_page(first);
             first = p2m_map_first(p2m, addr);
+            if ( !first )
+            {
+                rc = -EINVAL;
+                goto out;
+            }
             cur_first_page = p2m_first_level_index(addr);
         }
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 26 lines · Ian Campbell

The BUG_ON in p2m_map_first was over aggressive since the paddr_t can have come from the guest, via add_to_physmap. Instead return failure to the caller.

Also the check was simultaneously too lose. The valid offsets are 0..P2M_FIRST_ENTRIES-1 inclusive.

---
  xen/arch/arm/p2m.c |   10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
xen/arch/arm/p2m.c +2 -1
index 1d5c841..cd134d4 100644
@@ -58,7 +58,8 @@ static lpae_t *p2m_map_first(struct p2m_domain *p2m, paddr_t addr)
  {
      struct page_info *page;
 
-    BUG_ON(first_linear_offset(addr) > P2M_FIRST_ENTRIES);
+    if ( first_linear_offset(addr) >= P2M_FIRST_ENTRIES )
+        return NULL;
 
      page = p2m->first_level + p2m_first_level_index(addr);
 

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr) · line 85

Quoted 5 lines
xen/arch/arm/p2m.c +2 -0
@@ -80,6 +81,8 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr)
      spin_lock(&p2m->lock);
 
      first = p2m_map_first(p2m, paddr);
+    if ( !first )
+        goto done;

If you jump to done, you will use pte which is uninitialized. Unlock the spinlock should be enough here.

Signature · 1 line
Julien Grall
#2 lore raw
Quoted 9 lines · Julien Grall

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr) · line 85

Quoted 6 lines
xen/arch/arm/p2m.c +2 -0
@@ -80,6 +81,8 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr)
      spin_lock(&p2m->lock);
 
      first = p2m_map_first(p2m, paddr);
+    if ( !first )
+        goto done;

If you jump to done, you will use pte which is uninitialized. Unlock the spinlock should be enough here.

True. I wonder why the compiler didn't warn me about that, it's the sort of thing it normally spots.