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>
Acked-by: Julien Grall <julien.grall@linaro.org>
{
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);
spin_lock(&p2m->lock);
first = p2m_map_first(p2m, paddr);
+ if ( !first )
+ goto err;
pte = first[first_table_offset(paddr)];
if ( !pte.p2m.valid || !pte.p2m.table )
if (second) unmap_domain_page(second);
if (first) unmap_domain_page(first);
+err:
spin_unlock(&p2m->lock);
return maddr;
{
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);
}