Skip to contentSkip to conversation

x86, vsyscall: add CONFIG to control default

PATCH In review Kees Cook 5 participants 8 messages Aug 13, 2015 – Sep 21, 2015

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 x86, vsyscall: add CONFIG to control default

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

---
 arch/x86/Kconfig                      | 49 +++++++++++++++++++++++++++++++++++
 arch/x86/entry/vsyscall/vsyscall_64.c |  9 ++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)
arch/x86/Kconfig +49 -0
index b3a1a5d77d92..fbd0fad714a1 100644
@@ -2010,6 +2010,55 @@ config COMPAT_VDSO
 	  If unsure, say N: if you are compiling your own kernel, you
 	  are unlikely to be using a buggy version of glibc.
 
+choice
+	prompt "vsyscall table for legacy applications"
+	depends on X86_64
+	default LEGACY_VSYSCALL_EMULATE
+	help
+	  Legacy user code that does not know how to find the vDSO expects
+	  to be able to issue three syscalls by calling fixed addresses in
+	  kernel space. Since this location is not randomized with ASLR,
+	  it can be used to assist security vulnerability exploitation.
+
+	  This setting can be changed at boot time via the kernel command
+	  line parameter vsyscall=[native|emulate|none].
+
+	  On a system with recent enough glibc (2.14 or newer) and no
+	  static binaries, you can say None without a performance penalty
+	  to improve security.
+
+	  If unsure, select "Emulate".
+
+	config LEGACY_VSYSCALL_NATIVE
+		bool "Native"
+		help
+		  Actual executable code is located in the fixed vsyscall
+		  address mapping, implementing time() efficiently. Since
+		  this makes the mapping executable, it can be used during
+		  security vulnerability exploitation (traditionally as
+		  ROP gadgets). This configuration is not recommended.
+
+	config LEGACY_VSYSCALL_EMULATE
+		bool "Emulate"
+		help
+		  The kernel traps and emulates calls into the fixed
+		  vsyscall address mapping. This makes the mapping
+		  non-executable, but it still contains known contents,
+		  which could be used in certain rare security vulnerability
+		  exploits. This configuration is recommended when userspace
+		  still uses the vsyscall area.
+
+	config LEGACY_VSYSCALL_NONE
+		bool "None"
+		help
+		  There will be no vsyscall mapping at all. This will
+		  eliminate any risk of ASLR bypass due to the vsyscall
+		  fixed address mapping. Attempts to use the vsyscalls
+		  will be reported to dmesg, so that either old or
+		  malicious userspace programs can be identified.
+
+endchoice
+
 config CMDLINE_BOOL
 	bool "Built-in kernel command line"
 	---help---
arch/x86/entry/vsyscall/vsyscall_64.c +8 -1
index 2dcc6ff6fdcc..47e2904b043b 100644
@@ -38,7 +38,14 @@
 #define CREATE_TRACE_POINTS
 #include "vsyscall_trace.h"
 
-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
+static enum { EMULATE, NATIVE, NONE } vsyscall_mode =
+#ifdef CONFIG_LEGACY_VSYSCALL_NATIVE
+	NATIVE;
+#elif CONFIG_LEGACY_VSYSCALL_NONE
+	NONE;
+#else
+	EMULATE;
+#endif
 
 static int __init vsyscall_setup(char *str)
 {
Signature · 6 lines
1.9.1


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 6 lines · Kees Cook

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

Seems reasonable to me. One question, though: is there *any* reason to choose "native" over "emulate"? (Does "emulate" have a sufficient performance penalty to matter, and do people running old glibc really care about that performance while still not wanting to upgrade?) If there is a reason, could you please document it in the descriptions of the "native" and "emulate" options (as an upside and a downside, respectively)? If there isn't, you might consider a patch to remove "native".

Quoted 91 lines
 arch/x86/Kconfig                      | 49 +++++++++++++++++++++++++++++++++++
 arch/x86/entry/vsyscall/vsyscall_64.c |  9 ++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)
arch/x86/Kconfig +49 -0
index b3a1a5d77d92..fbd0fad714a1 100644
@@ -2010,6 +2010,55 @@ config COMPAT_VDSO
 	  If unsure, say N: if you are compiling your own kernel, you
 	  are unlikely to be using a buggy version of glibc.
 
+choice
+	prompt "vsyscall table for legacy applications"
+	depends on X86_64
+	default LEGACY_VSYSCALL_EMULATE
+	help
+	  Legacy user code that does not know how to find the vDSO expects
+	  to be able to issue three syscalls by calling fixed addresses in
+	  kernel space. Since this location is not randomized with ASLR,
+	  it can be used to assist security vulnerability exploitation.
+
+	  This setting can be changed at boot time via the kernel command
+	  line parameter vsyscall=[native|emulate|none].
+
+	  On a system with recent enough glibc (2.14 or newer) and no
+	  static binaries, you can say None without a performance penalty
+	  to improve security.
+
+	  If unsure, select "Emulate".
+
+	config LEGACY_VSYSCALL_NATIVE
+		bool "Native"
+		help
+		  Actual executable code is located in the fixed vsyscall
+		  address mapping, implementing time() efficiently. Since
+		  this makes the mapping executable, it can be used during
+		  security vulnerability exploitation (traditionally as
+		  ROP gadgets). This configuration is not recommended.
+
+	config LEGACY_VSYSCALL_EMULATE
+		bool "Emulate"
+		help
+		  The kernel traps and emulates calls into the fixed
+		  vsyscall address mapping. This makes the mapping
+		  non-executable, but it still contains known contents,
+		  which could be used in certain rare security vulnerability
+		  exploits. This configuration is recommended when userspace
+		  still uses the vsyscall area.
+
+	config LEGACY_VSYSCALL_NONE
+		bool "None"
+		help
+		  There will be no vsyscall mapping at all. This will
+		  eliminate any risk of ASLR bypass due to the vsyscall
+		  fixed address mapping. Attempts to use the vsyscalls
+		  will be reported to dmesg, so that either old or
+		  malicious userspace programs can be identified.
+
+endchoice
+
 config CMDLINE_BOOL
 	bool "Built-in kernel command line"
 	---help---
arch/x86/entry/vsyscall/vsyscall_64.c +8 -1
index 2dcc6ff6fdcc..47e2904b043b 100644
@@ -38,7 +38,14 @@
 #define CREATE_TRACE_POINTS
 #include "vsyscall_trace.h"
 
-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
+static enum { EMULATE, NATIVE, NONE } vsyscall_mode =
+#ifdef CONFIG_LEGACY_VSYSCALL_NATIVE
+	NATIVE;
+#elif CONFIG_LEGACY_VSYSCALL_NONE
+	NONE;
+#else
+	EMULATE;
+#endif
 
 static int __init vsyscall_setup(char *str)
 {
Signature · 6 lines
1.9.1


-- 
Kees Cook
Chrome OS Security
author
#2 lore raw
Quoted 8 lines · Josh Triplett
Quoted 6 lines · Kees Cook

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

Quoted 8 lines

Seems reasonable to me. One question, though: is there *any* reason to choose "native" over "emulate"? (Does "emulate" have a sufficient performance penalty to matter, and do people running old glibc really care about that performance while still not wanting to upgrade?) If there is a reason, could you please document it in the descriptions of the "native" and "emulate" options (as an upside and a downside, respectively)? If there isn't, you might consider a patch to remove "native".

I think "native" is available out of an abundance of caution. Andy left it available, though I'm not sure if he had plans to remove "native" entirely.

Can someone from the x86 tree take this patch, or are there other things to improve?

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#3 lore raw
Quoted 19 lines · Kees Cook
Quoted 8 lines · Josh Triplett
Quoted 6 lines · Kees Cook

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

Quoted 8 lines

Seems reasonable to me. One question, though: is there *any* reason to choose "native" over "emulate"? (Does "emulate" have a sufficient performance penalty to matter, and do people running old glibc really care about that performance while still not wanting to upgrade?) If there is a reason, could you please document it in the descriptions of the "native" and "emulate" options (as an upside and a downside, respectively)? If there isn't, you might consider a patch to remove "native".

Quoted 3 lines

I think "native" is available out of an abundance of caution. Andy left it available, though I'm not sure if he had plans to remove "native" entirely.

Native adds almost no code and almost no maintenance burden -- it's really just a PTE bit.

Quoted 3 lines

Can someone from the x86 tree take this patch, or are there other things to improve?

It looks good to me.

I was thinking about how to control vsyscalls per process, and it's not so easy. We can turn off emulation per process trivially (modulo figuring out the ABI), but the Project Zero thing makes me think that we want to be able to switch off *read* access.

For almost all purposes, we could just switch off read access globally with no ill effects. The problem is that nasty little programs like pin will start crashing when run on old binaries.

We could allocate two copies of the top pud, switch them out in the pgd depending on whether vsyscalls are on for the mm, and clearing the G bit. It's a bit of a departure for how things work now, and it'll interact really weirdly with the fixmap code and anything else that pokes at that part of the kernel page tables (e.g. Xen?) Hmm.

--Andy

author
#4 lore raw
Quoted 24 lines · Andy Lutomirski
Quoted 19 lines · Kees Cook
Quoted 8 lines · Josh Triplett
Quoted 6 lines · Kees Cook

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

Quoted 8 lines

Seems reasonable to me. One question, though: is there *any* reason to choose "native" over "emulate"? (Does "emulate" have a sufficient performance penalty to matter, and do people running old glibc really care about that performance while still not wanting to upgrade?) If there is a reason, could you please document it in the descriptions of the "native" and "emulate" options (as an upside and a downside, respectively)? If there isn't, you might consider a patch to remove "native".

Quoted 3 lines

I think "native" is available out of an abundance of caution. Andy left it available, though I'm not sure if he had plans to remove "native" entirely.

Quoted 8 lines

Native adds almost no code and almost no maintenance burden -- it's really just a PTE bit.

Quoted 3 lines

Can someone from the x86 tree take this patch, or are there other things to improve?

It looks good to me.

tglx, hpa, ingo? Can this go into -tip?

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#5 lore raw

[tip:x86/asm] x86/entry/vsyscall: Add CONFIG to control default

In reply to Kees Cook
x86/entry/vsyscall: Add CONFIG to control default
Commit-ID:  3dc33bd30f3e1c1bcaaafa3482737694debf0f0b
Gitweb:     http://git.kernel.org/tip/3dc33bd30f3e1c1bcaaafa3482737694debf0f0b
Author:     Kees Cook <[email protected]>
AuthorDate: Wed, 12 Aug 2015 17:55:19 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 20 Sep 2015 10:31:06 +0200

x86/entry/vsyscall: Add CONFIG to control default

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/Kconfig                      | 49 +++++++++++++++++++++++++++++++++++
 arch/x86/entry/vsyscall/vsyscall_64.c |  9 ++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)
arch/x86/Kconfig +49 -0
index 328c835..9bfb9e1 100644
@@ -2042,6 +2042,55 @@ config COMPAT_VDSO
 	  If unsure, say N: if you are compiling your own kernel, you
 	  are unlikely to be using a buggy version of glibc.
 
+choice
+	prompt "vsyscall table for legacy applications"
+	depends on X86_64
+	default LEGACY_VSYSCALL_EMULATE
+	help
+	  Legacy user code that does not know how to find the vDSO expects
+	  to be able to issue three syscalls by calling fixed addresses in
+	  kernel space. Since this location is not randomized with ASLR,
+	  it can be used to assist security vulnerability exploitation.
+
+	  This setting can be changed at boot time via the kernel command
+	  line parameter vsyscall=[native|emulate|none].
+
+	  On a system with recent enough glibc (2.14 or newer) and no
+	  static binaries, you can say None without a performance penalty
+	  to improve security.
+
+	  If unsure, select "Emulate".
+
+	config LEGACY_VSYSCALL_NATIVE
+		bool "Native"
+		help
+		  Actual executable code is located in the fixed vsyscall
+		  address mapping, implementing time() efficiently. Since
+		  this makes the mapping executable, it can be used during
+		  security vulnerability exploitation (traditionally as
+		  ROP gadgets). This configuration is not recommended.
+
+	config LEGACY_VSYSCALL_EMULATE
+		bool "Emulate"
+		help
+		  The kernel traps and emulates calls into the fixed
+		  vsyscall address mapping. This makes the mapping
+		  non-executable, but it still contains known contents,
+		  which could be used in certain rare security vulnerability
+		  exploits. This configuration is recommended when userspace
+		  still uses the vsyscall area.
+
+	config LEGACY_VSYSCALL_NONE
+		bool "None"
+		help
+		  There will be no vsyscall mapping at all. This will
+		  eliminate any risk of ASLR bypass due to the vsyscall
+		  fixed address mapping. Attempts to use the vsyscalls
+		  will be reported to dmesg, so that either old or
+		  malicious userspace programs can be identified.
+
+endchoice
+
 config CMDLINE_BOOL
 	bool "Built-in kernel command line"
 	---help---
arch/x86/entry/vsyscall/vsyscall_64.c +8 -1
index b160c0c..76e0fd3 100644
@@ -38,7 +38,14 @@
 #define CREATE_TRACE_POINTS
 #include "vsyscall_trace.h"
 
-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
+static enum { EMULATE, NATIVE, NONE } vsyscall_mode =
+#ifdef CONFIG_LEGACY_VSYSCALL_NATIVE
+	NATIVE;
+#elif CONFIG_LEGACY_VSYSCALL_NONE
+	NONE;
+#else
+	EMULATE;
+#endif
 
 static int __init vsyscall_setup(char *str)
 {
maintainer
#6 lore raw

Re: [tip:x86/asm] x86/entry/vsyscall: Add CONFIG to control default

Quoted 30 lines · tip-bot for Kees Cook
Commit-ID:  3dc33bd30f3e1c1bcaaafa3482737694debf0f0b
Gitweb:     http://git.kernel.org/tip/3dc33bd30f3e1c1bcaaafa3482737694debf0f0b
Author:     Kees Cook <[email protected]>
AuthorDate: Wed, 12 Aug 2015 17:55:19 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 20 Sep 2015 10:31:06 +0200

x86/entry/vsyscall: Add CONFIG to control default

Most modern systems can run with vsyscall=none. In an effort to provide a way for build-time defaults to lack legacy settings, this adds a new CONFIG to select the type of vsyscall mapping to use, similar to the existing "vsyscall" command line parameter.

Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/Kconfig                      | 49 +++++++++++++++++++++++++++++++++++
 arch/x86/entry/vsyscall/vsyscall_64.c |  9 ++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

...

arch/x86/entry/vsyscall/vsyscall_64.c line 44

Quoted 13 lines
arch/x86/entry/vsyscall/vsyscall_64.c +4 -1
index b160c0c..76e0fd3 100644
@@ -38,7 +38,14 @@
 #define CREATE_TRACE_POINTS
 #include "vsyscall_trace.h"
 
-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
+static enum { EMULATE, NATIVE, NONE } vsyscall_mode =
+#ifdef CONFIG_LEGACY_VSYSCALL_NATIVE
+	NATIVE;
+#elif CONFIG_LEGACY_VSYSCALL_NONE

My gcc complains about this. If it hasn't been fixed yet, here's a fix:

---
From: Borislav Petkov <[email protected]>
Date: Mon, 21 Sep 2015 09:34:23 +0200
Subject: [PATCH] x86/entry/vsyscall: Fix undefined symbol warning

3dc33bd30f3e1 ("x86/entry/vsyscall: Add CONFIG to control default") did the ifdef/elif thing but gcc doesn't like that:

arch/x86/entry/vsyscall/vsyscall_64.c:44:7: warning: "CONFIG_LEGACY_VSYSCALL_NONE" is not defined [-Wundef]
#elif CONFIG_LEGACY_VSYSCALL_NONE

         ^

Use defined() instead.

Cc Andy Lutomirski <[email protected]>
Cc Kees Cook <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/entry/vsyscall/vsyscall_64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/entry/vsyscall/vsyscall_64.c +2 -2
index 76e0fd3ea1fb..174c2549939d 100644
@@ -39,9 +39,9 @@
 #include "vsyscall_trace.h"
 
 static enum { EMULATE, NATIVE, NONE } vsyscall_mode =
-#ifdef CONFIG_LEGACY_VSYSCALL_NATIVE
+#if defined(CONFIG_LEGACY_VSYSCALL_NATIVE)
 	NATIVE;
-#elif CONFIG_LEGACY_VSYSCALL_NONE
+#elif defined(CONFIG_LEGACY_VSYSCALL_NONE)
 	NONE;
 #else
 	EMULATE;
Signature · 7 lines
2.1.4

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#7 lore raw

[tip:x86/asm] x86/entry/vsyscall: Fix undefined symbol warning

x86/entry/vsyscall: Fix undefined symbol warning
Commit-ID:  93f13a9f96771a064c716364aebc6e283b186eb8
Gitweb:     http://git.kernel.org/tip/93f13a9f96771a064c716364aebc6e283b186eb8
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 21 Sep 2015 09:48:29 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 21 Sep 2015 09:56:59 +0200

x86/entry/vsyscall: Fix undefined symbol warning

Commit:

3dc33bd30f3e1 ("x86/entry/vsyscall: Add CONFIG to control default")

did the ifdef/elif thing but GCC doesn't like that:

arch/x86/entry/vsyscall/vsyscall_64.c:44:7: warning: "CONFIG_LEGACY_VSYSCALL_NONE" is not defined [-Wundef]
#elif CONFIG_LEGACY_VSYSCALL_NONE

         ^

Use defined() instead.

Cc Andy Lutomirski <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/entry/vsyscall/vsyscall_64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/entry/vsyscall/vsyscall_64.c +2 -2
index 76e0fd3..174c254 100644
@@ -39,9 +39,9 @@
 #include "vsyscall_trace.h"
 
 static enum { EMULATE, NATIVE, NONE } vsyscall_mode =
-#ifdef CONFIG_LEGACY_VSYSCALL_NATIVE
+#if defined(CONFIG_LEGACY_VSYSCALL_NATIVE)
 	NATIVE;
-#elif CONFIG_LEGACY_VSYSCALL_NONE
+#elif defined(CONFIG_LEGACY_VSYSCALL_NONE)
 	NONE;
 #else
 	EMULATE;