Skip to contentSkip to conversation

Update cr3 in PAE mode when guest walk succeed but shadow walk fails

PATCH In review George Dunlap 5 participants 8 messages Oct 16, 2009 – Oct 21, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Update cr3 in PAE mode when guest walk succeed but shadow walk fails

When running in PAE mode, Windows 7 (apparently) will occasionally switch cr3 with one of the L3 entries invalid, make it valid, and then expect the hardware to load the new value. (This behavior is explicitly not promised in the hardware manuals.) This leads to a situation where on a shadow fault, the guest walk succeeds but the shadow walk fails. The code assumes this can only happen when the domain is dying, and makes an ASSERT() to that effect. So currently, in debug mode, this will cause the host to crash; in non-debug mode, this will cause a page-fault loop.

The attached patch solves the problem by calling update_cr3() in that path when the guest is in PAE mode, and only ASSERT()ing when the guest is not in PAE mode. The guest will get one spurious page fault, but subsequent accesses will succeed.

xen/arch/x86/mm/shadow/multi.c +9 -0
diff -r 4b78d565b535 xen/arch/x86/mm/shadow/multi.c
@@ -3194,7 +3194,16 @@
          * are OK, this can only have been caused by a failed
          * shadow_set_l*e(), which will have crashed the guest.
          * Get out of the fault handler immediately. */
+        /* Windows 7 apparently relies on the hardware to do something
+         * it explicitly hasn't promised to do: load l3 values after
+         * the cr3 is loaded.
+         * In any case, in the PAE case, the ASSERT is not true; it can
+         * happen because of actions the guest is taking. */
+#if GUEST_PAGING_LEVELS == 3
+        v->arch.paging.mode->update_cr3(v, 0);
+#else
         ASSERT(d->is_shutting_down);
+#endif
         shadow_unlock(d);
         trace_shadow_gen(TRC_SHADOW_DOMF_DYING, va);
         return 0;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines · George Dunlap

domain is dying, and makes an ASSERT() to that effect. So currently, in debug mode, this will cause the host to crash; in non-debug mode, this will cause a page-fault loop.

Isn't this a security hole then?

regards
john

#2 lore raw
Quoted 7 lines · John Levon
Quoted 3 lines · George Dunlap

domain is dying, and makes an ASSERT() to that effect. So currently, in debug mode, this will cause the host to crash; in non-debug mode, this will cause a page-fault loop.

Isn't this a security hole then?

Debug builds shouldn't be used in production environments. The page-fault loop, in the non-debug case, is preemptible, so the offending guest can only waste its own scheduling quantum.

-- Keir

#3 lore raw
Quoted 11 lines · Keir Fraser
Quoted 7 lines · George Dunlap
Quoted 4 lines

domain is dying, and makes an ASSERT() to that effect. So currently, in debug mode, this will cause the host to crash; in non-debug mode, this will cause a page-fault loop.

Isn't this a security hole then?

Debug builds shouldn't be used in production environments. The page-fault loop, in the non-debug case, is preemptible, so the offending guest can only waste its own scheduling quantum.

OK, makes sense.

regards
john

#4 lore raw
In reply to George Dunlap
Quoted 4 lines

The attached patch solves the problem by calling update_cr3() in that path when the guest is in PAE mode, and only ASSERT()ing when the guest is not in PAE mode. The guest will get one spurious page fault, but subsequent accesses will succeed.

Hi George,

I suppose this patch is also needed when running 32-on-64. In that case, shouldn't the test be

#if GUEST_PAGING_LEVELS >= 3

rather than "== 3"?

Thanks,

Paolo

#5 lore raw

Hi,

Quoted 6 lines · Paolo Bonzini

I suppose this patch is also needed when running 32-on-64. In that case, shouldn't the test be

#if GUEST_PAGING_LEVELS >= 3

rather than "== 3"?

No, '==' is correct. GUEST_PAGING_LEVELS refers to the layout of the _guest's_ pagetables, not the shadows. GUEST_PAGING_LEVELS == 4 means the guest is using full 64-bit pagetables, which don't have this quirk.

Cheers,

Tim,

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Citrix Systems (R&D) Ltd.
[Company #02300071, SL9 0DZ, UK.]
#6 lore raw
Quoted 6 lines · Tim Deegan

Hi,

Quoted 3 lines · Paolo Bonzini

I suppose this patch is also needed when running 32-on-64. In that case, shouldn't the test be

Quoted 7 lines
Quoted 3 lines

#if GUEST_PAGING_LEVELS>= 3

rather than "== 3"?

No, '==' is correct. GUEST_PAGING_LEVELS refers to the layout of the _guest's_ pagetables, not the shadows. GUEST_PAGING_LEVELS == 4 means the guest is using full 64-bit pagetables, which don't have this quirk.

Right, I should have read arch/x86/mm/shadow/Makefile.

Thanks,

Paolo

#7 lore raw
Quoted 2 lines · Paolo Bonzini

Right, I should have read arch/x86/mm/shadow/Makefile.

Yes, the shadow code is as sane as it can possibly be... but still barking mad by any standard. :-)

-George