Commit a67e7277 authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Ingo Molnar

x86/asm/entry: Add user_mode_ignore_vm86()

user_mode() is dangerous and user_mode_vm() has a confusing name.

Add user_mode_ignore_vm86() (equivalent to current user_mode()).
We'll change the small number of legitimate users of user_mode()
to user_mode_ignore_vm86().

Inspired by grsec, although this works rather differently.
Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brad Spengler <spender@grsecurity.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/202c56ca63823c338af8e2e54948dbe222da6343.1426728647.git.luto@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent e4518ab9
...@@ -121,6 +121,23 @@ static inline int user_mode_vm(struct pt_regs *regs) ...@@ -121,6 +121,23 @@ static inline int user_mode_vm(struct pt_regs *regs)
#endif #endif
} }
/*
* This is the fastest way to check whether regs come from user space.
* It is unsafe if regs might come from vm86 mode, though -- in vm86
* mode, all bits of CS and SS are completely under the user's control.
* The CPU considers vm86 mode to be CPL 3 regardless of CS and SS.
*
* Do NOT use this function unless you have already ruled out the
* possibility that regs came from vm86 mode.
*
* We check for RPL != 0 instead of RPL == 3 because we don't use rings
* 1 or 2 and this is more efficient.
*/
static inline int user_mode_ignore_vm86(struct pt_regs *regs)
{
return (regs->cs & SEGMENT_RPL_MASK) != 0;
}
static inline int v8086_mode(struct pt_regs *regs) static inline int v8086_mode(struct pt_regs *regs)
{ {
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment