x86/p2m: fix p2m_add_foreign error path

One of the error paths in p2m_add_foreign could call put_page with a
NULL page, thus triggering a fault.

Split the checks into two different if statements, so the appropriate
error path can be taken.

Fixes: 173ae32502 ('x86/p2m: tidy p2m_add_foreign() a little')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Roger Pau Monné authored and Andrew Cooper committed 2021-01-04 10:41:59 +00:00
1 parent 1516ecd6f5
commit 62dde2c1ef
1 file changed
+7 -2
+7 -2
View File
@@ -2601,8 +2601,13 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
* ram_rw | ram_logdirty | ram_ro | paging_out.
*/
page = get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC);
if ( !page ||
!p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )
if ( !page )
{
rc = -EINVAL;
goto out;
}
if ( !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )
{
rc = -EINVAL;
goto put_one;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.