diff options
author | Craig Bergstrom <craigb@google.com> | 2017-10-19 15:28:56 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-10-20 03:48:00 -0400 |
commit | ce56a86e2ade45d052b3228cdfebe913a1ae7381 (patch) | |
tree | 3ed469574e6ba78af76da7afef548aa6884626cf | |
parent | 7ac7f2c315ef76437f5119df354d334448534fb5 (diff) |
x86/mm: Limit mmap() of /dev/mem to valid physical addresses
Currently, it is possible to mmap() any offset from /dev/mem. If a
program mmaps() /dev/mem offsets outside of the addressable limits
of a system, the page table can be corrupted by setting reserved bits.
For example if you mmap() offset 0x0001000000000000 of /dev/mem on an
x86_64 system with a 48-bit bus, the page fault handler will be called
with error_code set to RSVD. The kernel then crashes with a page table
corruption error.
This change prevents this page table corruption on x86 by refusing
to mmap offsets higher than the highest valid address in the system.
Signed-off-by: Craig Bergstrom <craigb@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Toshi Kani <toshi.kani@hp.com>
Cc: dsafonov@virtuozzo.com
Cc: kirill.shutemov@linux.intel.com
Cc: mhocko@suse.com
Cc: oleg@redhat.com
Link: http://lkml.kernel.org/r/20171019192856.39672-1-craigb@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/include/asm/io.h | 4 | ||||
-rw-r--r-- | arch/x86/mm/mmap.c | 12 |
2 files changed, 16 insertions, 0 deletions
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h index c40a95c33bb8..322d25ae23ab 100644 --- a/arch/x86/include/asm/io.h +++ b/arch/x86/include/asm/io.h | |||
@@ -110,6 +110,10 @@ build_mmio_write(__writeq, "q", unsigned long, "r", ) | |||
110 | 110 | ||
111 | #endif | 111 | #endif |
112 | 112 | ||
113 | #define ARCH_HAS_VALID_PHYS_ADDR_RANGE | ||
114 | extern int valid_phys_addr_range(phys_addr_t addr, size_t size); | ||
115 | extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size); | ||
116 | |||
113 | /** | 117 | /** |
114 | * virt_to_phys - map virtual addresses to physical | 118 | * virt_to_phys - map virtual addresses to physical |
115 | * @address: address to remap | 119 | * @address: address to remap |
diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index a99679826846..320c6237e1d1 100644 --- a/arch/x86/mm/mmap.c +++ b/arch/x86/mm/mmap.c | |||
@@ -174,3 +174,15 @@ const char *arch_vma_name(struct vm_area_struct *vma) | |||
174 | return "[mpx]"; | 174 | return "[mpx]"; |
175 | return NULL; | 175 | return NULL; |
176 | } | 176 | } |
177 | |||
178 | int valid_phys_addr_range(phys_addr_t addr, size_t count) | ||
179 | { | ||
180 | return addr + count <= __pa(high_memory); | ||
181 | } | ||
182 | |||
183 | int valid_mmap_phys_addr_range(unsigned long pfn, size_t count) | ||
184 | { | ||
185 | phys_addr_t addr = (phys_addr_t)pfn << PAGE_SHIFT; | ||
186 | |||
187 | return valid_phys_addr_range(addr, count); | ||
188 | } | ||