aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/mm
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2012-10-01 10:18:46 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2012-10-09 08:16:57 -0400
commit5b1ba9e30cf0e259450da19189811eb140733f83 (patch)
tree033759c49f3159e9514e8b08282e41977477064c /arch/s390/mm
parent378b1e7a80a59325ca1036e892462db728126f84 (diff)
s390/mm,pageattr: add more page table walk sanity checks
The current page table walk code in pageattr.c only checks for large pages while walking the kernel page table, but happily assumes that everything else is just fine. Add more checks so we never access invalid memory regions. Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch/s390/mm')
-rw-r--r--arch/s390/mm/pageattr.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index 0f33bab3e984..b56953dd95f8 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -8,25 +8,38 @@
8#include <asm/cacheflush.h> 8#include <asm/cacheflush.h>
9#include <asm/pgtable.h> 9#include <asm/pgtable.h>
10 10
11static pte_t *walk_page_table(unsigned long addr)
12{
13 pgd_t *pgdp;
14 pud_t *pudp;
15 pmd_t *pmdp;
16 pte_t *ptep;
17
18 pgdp = pgd_offset_k(addr);
19 if (pgd_none(*pgdp))
20 return NULL;
21 pudp = pud_offset(pgdp, addr);
22 if (pud_none(*pudp))
23 return NULL;
24 pmdp = pmd_offset(pudp, addr);
25 if (pmd_none(*pmdp) || pmd_large(*pmdp))
26 return NULL;
27 ptep = pte_offset_kernel(pmdp, addr);
28 if (pte_none(*ptep))
29 return NULL;
30 return ptep;
31}
32
11static void change_page_attr(unsigned long addr, int numpages, 33static void change_page_attr(unsigned long addr, int numpages,
12 pte_t (*set) (pte_t)) 34 pte_t (*set) (pte_t))
13{ 35{
14 pte_t *ptep, pte; 36 pte_t *ptep, pte;
15 pmd_t *pmdp;
16 pud_t *pudp;
17 pgd_t *pgdp;
18 int i; 37 int i;
19 38
20 for (i = 0; i < numpages; i++) { 39 for (i = 0; i < numpages; i++) {
21 pgdp = pgd_offset(&init_mm, addr); 40 ptep = walk_page_table(addr);
22 pudp = pud_offset(pgdp, addr); 41 if (WARN_ON_ONCE(!ptep))
23 pmdp = pmd_offset(pudp, addr); 42 break;
24 if (pmd_large(*pmdp)) {
25 WARN_ON_ONCE(1);
26 continue;
27 }
28 ptep = pte_offset_kernel(pmdp, addr);
29
30 pte = *ptep; 43 pte = *ptep;
31 pte = set(pte); 44 pte = set(pte);
32 __ptep_ipte(addr, ptep); 45 __ptep_ipte(addr, ptep);