x86/pv: Track and flush non-coherent mappings of RAM
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 9 Jun 2022 12:23:37 +0000 (14:23 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 9 Jun 2022 12:23:37 +0000 (14:23 +0200)
commitc1c9cae3a9633054b177c5de21ad7268162b2f2c
treef623330221f47045fa191186c6119355d691a0c6
parent062868a5a8b428b85db589fa9a6d6e43969ffeb9
x86/pv: Track and flush non-coherent mappings of RAM

There are legitimate uses of WC mappings of RAM, e.g. for DMA buffers with
devices that make non-coherent writes.  The Linux sound subsystem makes
extensive use of this technique.

For such usecases, the guest's DMA buffer is mapped and consistently used as
WC, and Xen doesn't interact with the buffer.

However, a mischevious guest can use WC mappings to deliberately create
non-coherency between the cache and RAM, and use this to trick Xen into
validating a pagetable which isn't actually safe.

Allocate a new PGT_non_coherent to track the non-coherency of mappings.  Set
it whenever a non-coherent writeable mapping is created.  If the page is used
as anything other than PGT_writable_page, force a cache flush before
validation.  Also force a cache flush before the page is returned to the heap.

This is CVE-2022-26364, part of XSA-402.

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/include/asm/mm.h
xen/arch/x86/mm.c
xen/arch/x86/pv/grant_table.c