From: Steven Price <steven.pr...@arm.com>

[ Upstream commit c02a98753e0a36ba65a05818626fa6adeb4e7c97 ]

If walk_pte_range() is called with a 'end' argument that is beyond the
last page of memory (e.g.  ~0UL) then the comparison between 'addr' and
'end' will always fail and the loop will be infinite.  Instead change the
comparison to >= while accounting for overflow.

Link: http://lkml.kernel.org/r/20191218162402.45610-15-steven.pr...@arm.com
Signed-off-by: Steven Price <steven.pr...@arm.com>
Cc: Albert Ou <a...@eecs.berkeley.edu>
Cc: Alexandre Ghiti <a...@ghiti.fr>
Cc: Andy Lutomirski <l...@kernel.org>
Cc: Ard Biesheuvel <ard.biesheu...@linaro.org>
Cc: Arnd Bergmann <a...@arndb.de>
Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org>
Cc: Borislav Petkov <b...@alien8.de>
Cc: Catalin Marinas <catalin.mari...@arm.com>
Cc: Christian Borntraeger <borntrae...@de.ibm.com>
Cc: Dave Hansen <dave.han...@linux.intel.com>
Cc: David S. Miller <da...@davemloft.net>
Cc: Heiko Carstens <heiko.carst...@de.ibm.com>
Cc: "H. Peter Anvin" <h...@zytor.com>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: James Hogan <jho...@kernel.org>
Cc: James Morse <james.mo...@arm.com>
Cc: Jerome Glisse <jgli...@redhat.com>
Cc: "Liang, Kan" <kan.li...@linux.intel.com>
Cc: Mark Rutland <mark.rutl...@arm.com>
Cc: Michael Ellerman <m...@ellerman.id.au>
Cc: Paul Burton <paul.bur...@mips.com>
Cc: Paul Mackerras <pau...@samba.org>
Cc: Paul Walmsley <paul.walms...@sifive.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Ralf Baechle <r...@linux-mips.org>
Cc: Russell King <li...@armlinux.org.uk>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Vasily Gorbik <g...@linux.ibm.com>
Cc: Vineet Gupta <vgu...@synopsys.com>
Cc: Will Deacon <w...@kernel.org>
Cc: Zong Li <zong...@sifive.com>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 mm/pagewalk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index c2cbd26201696..a024667a9c041 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -14,9 +14,9 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, 
unsigned long end,
                err = walk->pte_entry(pte, addr, addr + PAGE_SIZE, walk);
                if (err)
                       break;
-               addr += PAGE_SIZE;
-               if (addr == end)
+               if (addr >= end - PAGE_SIZE)
                        break;
+               addr += PAGE_SIZE;
                pte++;
        }
 
-- 
2.25.1

Reply via email to