[PATCH] x86: strengthen 64-bit p?d_bad()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Hugh Dickins
Date: Tuesday, May 20, 2008 - 5:59 am

The x86_64 pgd_bad(), pud_bad(), pmd_bad() inlines have differed from
their x86_32 counterparts in a couple of ways: they've been unnecessarily
weak (e.g. letting 0 or 1 count as good), and were typed as unsigned long.
Strengthen them and return int.

The PAE pmd_bad was too weak before, allowing any junk in the upper half;
but got strengthened by the patch correcting its ~PAGE_MASK to ~PTE_MASK.
The PAE pud_bad already said ~PTE_MASK; and since it folds into pgd_bad,
and we don't set the protection bits at that level, it'll do as is.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
This could either go in along with Jeremy's PTE_MASK patches, or be
held back for next release - it's independent of them, and not vital.

 include/asm-x86/pgtable_64.h |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

--- a/include/asm-x86/pgtable_64.h
+++ b/include/asm-x86/pgtable_64.h
@@ -151,19 +151,19 @@ static inline void native_pgd_clear(pgd_
 
 #ifndef __ASSEMBLY__
 
-static inline unsigned long pgd_bad(pgd_t pgd)
+static inline int pgd_bad(pgd_t pgd)
 {
-	return pgd_val(pgd) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
+	return (pgd_val(pgd) & ~(PTE_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
-static inline unsigned long pud_bad(pud_t pud)
+static inline int pud_bad(pud_t pud)
 {
-	return pud_val(pud) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
+	return (pud_val(pud) & ~(PTE_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
-static inline unsigned long pmd_bad(pmd_t pmd)
+static inline int pmd_bad(pmd_t pmd)
 {
-	return pmd_val(pmd) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
+	return (pmd_val(pmd) & ~(PTE_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
 #define pte_none(x)	(!pte_val((x)))
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0 of 8] x86: use PTE_MASK consistently, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 1 of 8] x86: define PTE_MASK in a universally usefu ..., Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 2 of 8] x86: fix warning on 32-bit non-PAE, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 3 of 8] x86: rearrange __(VIRTUAL|PHYSICAL)_MASK, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 4 of 8] x86: use PTE_MASK in 32-bit PAE, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 5 of 8] x86: use PTE_MASK in pgtable_32.h, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 6 of 8] x86: clarify use of _PAGE_CHG_MASK, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 7 of 8] x86: use PTE_MASK rather than ad-hoc mask, Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
[PATCH 8 of 8] xen: use PTE_MASK in pte_mfn(), Jeremy Fitzhardinge, (Tue May 20, 12:26 am)
Re: [PATCH 0 of 8] x86: use PTE_MASK consistently, Hugh Dickins, (Tue May 20, 5:57 am)
[PATCH] x86: strengthen 64-bit p?d_bad(), Hugh Dickins, (Tue May 20, 5:59 am)
Re: [PATCH 0 of 8] x86: use PTE_MASK consistently, Jeremy Fitzhardinge, (Tue May 20, 6:47 am)
Re: [PATCH 0 of 8] x86: use PTE_MASK consistently, Linus Torvalds, (Tue May 20, 11:34 am)
Re: [PATCH 0 of 8] x86: use PTE_MASK consistently, Ingo Molnar, (Tue May 20, 12:51 pm)
Re: [PATCH 0 of 8] x86: use PTE_MASK consistently, Ingo Molnar, (Tue May 20, 12:55 pm)
Re: [PATCH 0 of 8] x86: use PTE_MASK consistently, Linus Torvalds, (Tue May 20, 1:02 pm)