kernel: copy generic to kernel 5.2
[openwrt/staging/mkresin.git] / target / linux / generic / pending-5.2 / 303-MIPS-Fix-bounds-check-virt_addr_valid.patch
1 From 415e0feec4f927af0059f72a6831f6c5a104f0fc Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Mon, 17 Jun 2019 00:13:08 +0200
4 Subject: [PATCH] MIPS: Fix bounds check virt_addr_valid
5
6 The bounds check used the uninitialized variable vaddr, it should use
7 the given parameter kaddr instead. When using the uninitialized value
8 the compiler assumed it to be 0 and optimized this function to just
9 return 0 in all cases.
10
11 This should make the function check the range of the given address and
12 only do the page map check in case it is in the expected range of
13 virtual addresses.
14
15 Fixes: 074a1e1167af ("MIPS: Bounds check virt_addr_valid")
16 Cc: stable@vger.kernel.org # v4.12+
17 Cc: Paul Burton <paul.burton@mips.com>
18 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
19 ---
20 arch/mips/mm/mmap.c | 2 +-
21 1 file changed, 1 insertion(+), 1 deletion(-)
22
23 --- a/arch/mips/mm/mmap.c
24 +++ b/arch/mips/mm/mmap.c
25 @@ -203,7 +203,7 @@ unsigned long arch_randomize_brk(struct
26
27 int __virt_addr_valid(const volatile void *kaddr)
28 {
29 - unsigned long vaddr = (unsigned long)vaddr;
30 + unsigned long vaddr = (unsigned long)kaddr;
31
32 if ((vaddr < PAGE_OFFSET) || (vaddr >= MAP_BASE))
33 return 0;