diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-05-03 16:14:14 -0400 |
---|---|---|
committer | Luis Henriques <luis.henriques@canonical.com> | 2012-05-25 12:24:42 -0400 |
commit | 7bcb7a821a85b21f87fea2a430f44458ca091a03 (patch) | |
tree | 32218b8efd133d4affda38e07d85f858863b5e9e | |
parent | 07f2e5b40c98a18e0463c6ae90e2c3812ae86e67 (diff) |
xen/pte: Fix crashes when trying to see non-existent PGD/PMD/PUD/PTEs
BugLink: http://bugs.launchpad.net/bugs/1002880
commit b7e5ffe5d83fa40d702976d77452004abbe35791 upstream.
If I try to do "cat /sys/kernel/debug/kernel_page_tables"
I end up with:
BUG: unable to handle kernel paging request at ffffc7fffffff000
IP: [<ffffffff8106aa51>] ptdump_show+0x221/0x480
PGD 0
Oops: 0000 [#1] SMP
CPU 0
.. snip..
RAX: 0000000000000000 RBX: ffffc00000000fff RCX: 0000000000000000
RDX: 0000800000000000 RSI: 0000000000000000 RDI: ffffc7fffffff000
which is due to the fact we are trying to access a PFN that is not
accessible to us. The reason (at least in this case) was that
PGD[256] is set to __HYPERVISOR_VIRT_START which was setup (by the
hypervisor) to point to a read-only linear map of the MFN->PFN array.
During our parsing we would get the MFN (a valid one), try to look
it up in the MFN->PFN tree and find it invalid and return ~0 as PFN.
Then pte_mfn_to_pfn would happilly feed that in, attach the flags
and return it back to the caller. 'ptdump_show' bitshifts it and
gets and invalid value that it tries to dereference.
Instead of doing all of that, we detect the ~0 case and just
return !_PAGE_PRESENT.
This bug has been in existence .. at least until 2.6.37 (yikes!)
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
-rw-r--r-- | arch/x86/xen/mmu.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index 5f76c0acb2c..d957dce61ed 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c | |||
@@ -320,8 +320,13 @@ static pteval_t pte_mfn_to_pfn(pteval_t val) | |||
320 | { | 320 | { |
321 | if (val & _PAGE_PRESENT) { | 321 | if (val & _PAGE_PRESENT) { |
322 | unsigned long mfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; | 322 | unsigned long mfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; |
323 | unsigned long pfn = mfn_to_pfn(mfn); | ||
324 | |||
323 | pteval_t flags = val & PTE_FLAGS_MASK; | 325 | pteval_t flags = val & PTE_FLAGS_MASK; |
324 | val = ((pteval_t)mfn_to_pfn(mfn) << PAGE_SHIFT) | flags; | 326 | if (unlikely(pfn == ~0)) |
327 | val = flags & ~_PAGE_PRESENT; | ||
328 | else | ||
329 | val = ((pteval_t)pfn << PAGE_SHIFT) | flags; | ||
325 | } | 330 | } |
326 | 331 | ||
327 | return val; | 332 | return val; |