xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen: arm: do not BUG on guest paddrs which are very high
@ 2013-12-05 12:53 Ian Campbell
  2013-12-06 16:05 ` Julien Grall
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Campbell @ 2013-12-05 12:53 UTC (permalink / raw)
  To: xen-devel; +Cc: julien.grall, tim, Ian Campbell, stefano.stabellini

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.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 xen/arch/arm/p2m.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 1d5c841..cd134d4 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -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);
         }
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xen: arm: do not BUG on guest paddrs which are very high
  2013-12-05 12:53 [PATCH] xen: arm: do not BUG on guest paddrs which are very high Ian Campbell
@ 2013-12-06 16:05 ` Julien Grall
  2013-12-06 17:05   ` Ian Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Grall @ 2013-12-06 16:05 UTC (permalink / raw)
  To: Ian Campbell, xen-devel; +Cc: tim, stefano.stabellini



On 12/05/2013 12:53 PM, Ian Campbell wrote:
> 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.
>
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> ---
>   xen/arch/arm/p2m.c |   10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index 1d5c841..cd134d4 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -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;

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

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xen: arm: do not BUG on guest paddrs which are very high
  2013-12-06 16:05 ` Julien Grall
@ 2013-12-06 17:05   ` Ian Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2013-12-06 17:05 UTC (permalink / raw)
  To: Julien Grall; +Cc: stefano.stabellini, tim, xen-devel

On Fri, 2013-12-06 at 16:05 +0000, Julien Grall wrote:
> > @@ -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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-06 17:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05 12:53 [PATCH] xen: arm: do not BUG on guest paddrs which are very high Ian Campbell
2013-12-06 16:05 ` Julien Grall
2013-12-06 17:05   ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).