From: Harvey Harrison <harvey.harrison@gmail.com>
To: Ingo Molnar <mingo@elte.hu>, Andi Kleen <ak@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] x86: Unify pte_exec helper
Date: Tue, 15 Jan 2008 13:42:36 -0800 [thread overview]
Message-ID: <1200433356.16794.52.camel@brick> (raw)
- Rename it to pte_exec() from pte_exec_kernel(). There is nothing
kernel specific in there.
- Move it into the common file because _PAGE_NX is 0 on !PAE and then
pte_exec() will be always evaluate to true.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Taken from Patch 31/31 in Andi's CPA queue, added the init_32 change
as well. Against x86.git
arch/x86/mm/fault_32.c | 2 +-
arch/x86/mm/init_32.c | 2 +-
include/asm-x86/pgtable-2level.h | 8 --------
include/asm-x86/pgtable-3level.h | 8 --------
include/asm-x86/pgtable.h | 1 +
5 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/arch/x86/mm/fault_32.c b/arch/x86/mm/fault_32.c
index 977904c..936bb0c 100644
--- a/arch/x86/mm/fault_32.c
+++ b/arch/x86/mm/fault_32.c
@@ -615,7 +615,7 @@ no_context:
if (error_code & PF_INSTR) {
pte_t *pte = lookup_address(address);
- if (pte && pte_present(*pte) && !pte_exec_kernel(*pte))
+ if (pte && pte_present(*pte) && !pte_exec(*pte))
printk(KERN_CRIT "kernel tried to execute "
"NX-protected page - exploit attempt? "
"(uid: %d)\n", current->uid);
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index b8ba6a7..2456968 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -613,7 +613,7 @@ int __init set_kernel_exec(unsigned long vaddr, int enable)
pte = lookup_address(vaddr);
BUG_ON(!pte);
- if (!pte_exec_kernel(*pte))
+ if (!pte_exec(*pte))
ret = 0;
if (enable)
diff --git a/include/asm-x86/pgtable-2level.h b/include/asm-x86/pgtable-2level.h
index ce486bd..701404f 100644
--- a/include/asm-x86/pgtable-2level.h
+++ b/include/asm-x86/pgtable-2level.h
@@ -56,14 +56,6 @@ static inline pte_t native_ptep_get_and_clear(pte_t *xp)
#define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
/*
- * All present pages are kernel-executable:
- */
-static inline int pte_exec_kernel(pte_t pte)
-{
- return 1;
-}
-
-/*
* Bits 0, 6 and 7 are taken, split up the 29 bits of offset
* into this range:
*/
diff --git a/include/asm-x86/pgtable-3level.h b/include/asm-x86/pgtable-3level.h
index bfafa9b..20fc120 100644
--- a/include/asm-x86/pgtable-3level.h
+++ b/include/asm-x86/pgtable-3level.h
@@ -19,14 +19,6 @@
#define pud_bad(pud) 0
#define pud_present(pud) 1
-/*
- * All present pages with !NX bit are kernel-executable:
- */
-static inline int pte_exec_kernel(pte_t pte)
-{
- return !(pte_val(pte) & _PAGE_NX);
-}
-
/* Rules for using set_pte: the pte being assigned *must* be
* either not present or in a state where the hardware will
* not attempt to update the pte. In places where this is
diff --git a/include/asm-x86/pgtable.h b/include/asm-x86/pgtable.h
index bae9648..dce27bb 100644
--- a/include/asm-x86/pgtable.h
+++ b/include/asm-x86/pgtable.h
@@ -142,6 +142,7 @@ static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;
static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_PSE; }
+static inline int pte_exec(pte_t pte) { return !(pte_val(pte) & _PAGE_NX); }
static inline int pmd_large(pmd_t pte) {
return (pmd_val(pte) & (_PAGE_PSE|_PAGE_PRESENT)) ==
--
1.5.4.rc2.1164.g6451
reply other threads:[~2008-01-15 21:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1200433356.16794.52.camel@brick \
--to=harvey.harrison@gmail.com \
--cc=ak@suse.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.