All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/p2m: fix p2m_add_foreign error path
@ 2021-01-04  9:03 Roger Pau Monne
  2021-01-04 10:45 ` Andrew Cooper
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Pau Monne @ 2021-01-04  9:03 UTC (permalink / raw)
  To: xen-devel
  Cc: Roger Pau Monne, Jan Beulich, Andrew Cooper, George Dunlap, Wei Liu

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: 173ae325026bd ('x86/p2m: tidy p2m_add_foreign() a little')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/mm/p2m.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 487959b121..a4ebfc9b21 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -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;
-- 
2.29.2



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

* Re: [PATCH] x86/p2m: fix p2m_add_foreign error path
  2021-01-04  9:03 [PATCH] x86/p2m: fix p2m_add_foreign error path Roger Pau Monne
@ 2021-01-04 10:45 ` Andrew Cooper
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Cooper @ 2021-01-04 10:45 UTC (permalink / raw)
  To: Roger Pau Monne, xen-devel; +Cc: Jan Beulich, George Dunlap, Wei Liu

On 04/01/2021 09:03, Roger Pau Monne wrote:
> 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: 173ae325026bd ('x86/p2m: tidy p2m_add_foreign() a little')
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Acked and committed.

~Andrew


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

end of thread, other threads:[~2021-01-04 10:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04  9:03 [PATCH] x86/p2m: fix p2m_add_foreign error path Roger Pau Monne
2021-01-04 10:45 ` Andrew Cooper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.