Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 5bbd952

Browse files
Ard BiesheuvelGraeme Gregory
Ard Biesheuvel
authored and
Graeme Gregory
committed
arm64: kernel: restrict /dev/mem read() calls to linear region
When running lscpu on an AArch64 system that has SMBIOS version 2.0 tables, it will segfault in the following way: Unable to handle kernel paging request at virtual address ffff8000bfff0000 pgd = ffff8000f9615000 [ffff8000bfff0000] *pgd=0000000000000000 Internal error: Oops: 96000007 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1284 Comm: lscpu Not tainted 4.11.0-rc3+ torvalds#103 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 task: ffff8000fa78e800 task.stack: ffff8000f9780000 PC is at __arch_copy_to_user+0x90/0x220 LR is at read_mem+0xcc/0x140 This is caused by the fact that lspci issues a read() on /dev/mem at the offset where it expects to find the SMBIOS structure array. However, this region is classified as EFI_RUNTIME_SERVICE_DATA (as per the UEFI spec), and so it is omitted from the linear mapping. So let's restrict /dev/mem read/write access to those areas that are covered by the linear region. Reported-by: Alexander Graf <[email protected]> Fixes: 4dffbfc ("arm64/efi: mark UEFI reserved regions as MEMBLOCK_NOMAP") Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Graeme Gregory <[email protected]>
1 parent c0bc126 commit 5bbd952

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: arch/arm64/mm/mmap.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <linux/elf.h>
2020
#include <linux/fs.h>
21+
#include <linux/memblock.h>
2122
#include <linux/mm.h>
2223
#include <linux/mman.h>
2324
#include <linux/export.h>
@@ -103,12 +104,18 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
103104
*/
104105
int valid_phys_addr_range(phys_addr_t addr, size_t size)
105106
{
106-
if (addr < PHYS_OFFSET)
107-
return 0;
108-
if (addr + size > __pa(high_memory - 1) + 1)
109-
return 0;
110-
111-
return 1;
107+
/*
108+
* Check whether addr is covered by a memory region without the
109+
* MEMBLOCK_NOMAP attribute, and whether that region covers the
110+
* entire range. In theory, this could lead to false negatives
111+
* if the range is covered by distinct but adjacent memory regions
112+
* that only differ in other attributes. However, few of such
113+
* attributes have been defined, and it is debatable whether it
114+
* follows that /dev/mem read() calls should be able traverse
115+
* such boundaries.
116+
*/
117+
return memblock_is_region_memory(addr, size) &&
118+
memblock_is_map_memory(addr);
112119
}
113120

114121
/*

0 commit comments

Comments
 (0)