linux-stable/arch/mips/mm
Paul Burton 3901e8368c MIPS: Bounds check virt_addr_valid
commit 074a1e1167 upstream.

The virt_addr_valid() function is meant to return true iff
virt_to_page() will return a valid struct page reference. This is true
iff the address provided is found within the unmapped address range
between PAGE_OFFSET & MAP_BASE, but we don't currently check for that
condition. Instead we simply mask the address to obtain what will be a
physical address if the virtual address is indeed in the desired range,
shift it to form a PFN & then call pfn_valid(). This can incorrectly
return true if called with a virtual address which, after masking,
happens to form a physical address corresponding to a valid PFN.

For example we may vmalloc an address in the kernel mapped region
starting a MAP_BASE & obtain the virtual address:

  addr = 0xc000000000002000

When masked by virt_to_phys(), which uses __pa() & in turn CPHYSADDR(),
we obtain the following (bogus) physical address:

  addr = 0x2000

In a common system with PHYS_OFFSET=0 this will correspond to a valid
struct page which should really be accessed by virtual address
PAGE_OFFSET+0x2000, causing virt_addr_valid() to incorrectly return 1
indicating that the original address corresponds to a struct page.

This is equivalent to the ARM64 change made in commit ca219452c6
("arm64: Correctly bounds check virt_addr_valid").

This fixes fallout when hardened usercopy is enabled caused by the
related commit 517e1fbeb6 ("mm/usercopy: Drop extra
is_vmalloc_or_module() check") which removed a check for the vmalloc
range that was present from the introduction of the hardened usercopy
feature.

Signed-off-by: Paul Burton <paul.burton@mips.com>
References: ca219452c6 ("arm64: Correctly bounds check virt_addr_valid")
References: 517e1fbeb6 ("mm/usercopy: Drop extra is_vmalloc_or_module() check")
Reported-by: Julien Cristau <jcristau@debian.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: YunQiang Su <ysu@wavecomp.com>
URL: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929366
Cc: stable@vger.kernel.org # v4.12+
Cc: linux-mips@vger.kernel.org
Cc: Yunqiang Su <ysu@wavecomp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-11 12:21:48 +02:00
..
c-octeon.c MIPS: c-r4k: Split user/kernel flush_icache_range() 2016-10-04 16:13:57 +02:00
c-r3k.c MIPS: Expand MIPS32 ASIDs to 64 bits 2019-01-09 17:14:52 +01:00
c-r4k.c MIPS: c-r4k: Add r4k_blast_scache_node for Loongson-3 2019-01-09 17:14:52 +01:00
c-tx39.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cache.c MIPS: Remove __invalidate_kernel_vmap_range 2017-08-29 15:21:55 +02:00
cerr-sb1.c
cex-gen.S
cex-oct.S
cex-sb1.S
dma-default.c MIPS: Declare various variables & functions static 2017-08-29 15:21:55 +02:00
extable.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
fault.c MIPS: Remove confusing else statement in __do_page_fault() 2017-04-13 00:47:04 +02:00
gup.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
highmem.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hugetlbpage.c mm/hugetlb: add size parameter to huge_pte_offset() 2017-07-06 16:24:34 -07:00
init.c MIPS: Include linux/initrd.h for free_initrd_mem() 2017-08-29 15:21:54 +02:00
ioremap.c MIPS: Fix ioremap() RAM check 2018-07-17 11:39:23 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mmap.c MIPS: Bounds check virt_addr_valid 2019-06-11 12:21:48 +02:00
page-funcs.S MIPS: Export {copy, clear}_page functions alongside their definitions 2017-01-03 16:48:39 +01:00
page.c MIPS: Export {copy, clear}_page functions alongside their definitions 2017-01-03 16:48:39 +01:00
pgtable-32.c MIPS: mm: fixed mappings: correct initialisation 2017-06-08 14:51:58 +02:00
pgtable-64.c MIPS: Add 48-bit VA space (and 4-level page tables) for 4K pages. 2017-04-10 11:56:06 +02:00
pgtable.c MIPS: Move pgd_alloc() out of header 2017-02-02 15:06:26 +00:00
sc-debugfs.c Update MIPS email addresses 2017-11-03 09:02:30 -07:00
sc-ip22.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sc-mips.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sc-r5k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sc-rm7k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tlb-funcs.S
tlb-r3k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tlb-r4k.c MIPS: Mask out limit field when calculating wired entry count 2016-11-24 16:44:16 +01:00
tlb-r8k.c MIPS: Retrieve ASID masks using function accepting struct cpuinfo_mips 2016-05-13 14:02:20 +02:00
tlbex-fault.S MIPS: Add DWARF unwinding to assembly 2017-09-06 11:01:52 +02:00
tlbex.c MIPS: Remove unused R6000 support 2017-08-29 15:21:51 +02:00
uasm-micromips.c MIPS: microMIPS: Fix incorrect mask in insn_table_MM 2017-11-01 00:09:16 +00:00
uasm-mips.c MIPS: mm: remove duplicate "const" qualifier on insn_table 2017-08-07 11:57:30 +02:00
uasm.c MIPS: Add some instructions to uasm. 2017-06-28 12:22:39 +02:00