[PATCH v2] mm: Fix possible off-by-one in walk_pte_range()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Mikael Pettersson <mikpe@...>
Cc: LKML <linux-kernel@...>, Roel Kluin <12o3l@...>, Andreas Schwab <schwab@...>, Matt Mackall <mpm@...>, Andrew Morton <akpm@...>
Date: Tuesday, April 15, 2008 - 12:16 pm

Hi,

Mikael Pettersson <mikpe@it.uu.se> writes:


Sorry, I think too lispy :)

	Hannes
---

From: Johannes Weiner <hannes@saeurebad.de>
Subject: [PATCH] mm: Fix possible off-by-one in walk_pte_range()

After the loop in walk_pte_range() pte might point to the first address
after the pmd it walks.  The pte_unmap() is then applied to something
bad.

Spotted by Roel Kluin and Andreas Schwab.

Signed-off-by: Johannes Weiner <hannes@saeurebad.de>
CC: Roel Kluin <12o3l@tiscali.nl>
CC: Andreas Schwab <schwab@suse.de>
CC: Matt Mackall <mpm@selenic.com>
CC: Andrew Morton <akpm@linux-foundation.org>
---

A bug is unlikely, though.  kunmap_atomic() looks up the kmap entry by
map-type instead of the address the pte points.  So the worst thing I
could find with a quick grep was that a wrong TLB entry is being
flushed.  Still, the code is wrong :)

diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index 1cf1417..0afd238 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -9,11 +9,15 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 	int err = 0;
 
 	pte = pte_offset_map(pmd, addr);
-	do {
+	for (;;) {
 		err = walk->pte_entry(pte, addr, addr + PAGE_SIZE, private);
 		if (err)
 		       break;
-	} while (pte++, addr += PAGE_SIZE, addr != end);
+		addr += PAGE_SIZE;
+		if (addr == end)
+			break;
+		pte++;
+	}
 
 	pte_unmap(pte);
 	return err;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] mm: Fix possible off-by-one in walk_pte_range(), Johannes Weiner, (Tue Apr 15, 10:00 am)
Re: [PATCH] mm: Fix possible off-by-one in walk_pte_range(), Mikael Pettersson, (Tue Apr 15, 11:36 am)
[PATCH v2] mm: Fix possible off-by-one in walk_pte_range(), Johannes Weiner, (Tue Apr 15, 12:16 pm)
Re: [PATCH v2] mm: Fix possible off-by-one in walk_pte_range(), Mikael Pettersson, (Wed Apr 16, 3:48 am)