From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 3/3] xen/x86: Use non-canonical pointers for ERR_PTR() errors
Date: Tue, 1 Nov 2016 10:46:10 +0000 [thread overview]
Message-ID: <1477997170-7795-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1477997170-7795-1-git-send-email-andrew.cooper3@citrix.com>
The top of the virutal address space is owned by 64bit PV kernels. Code which
fails to correctly check an ERR_PTR() value might follow the pointer into
guest space.
Mitigate this risk by sliding the ERR_PTR() error range into the non-canonical
region.
As this comes with a small overhead, and isn't necessary if 64bit PV guests
aren't used, provide a Kconfig opt-out for power users.
As an example, ERR_PTR(-EINVAL) has the value 0xbad0eee0ffffffea.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
Ideally, the constant would read "bad err", but r's are hard in hex.
Alternative constant suggestions welcome.
---
xen/arch/x86/Kconfig | 18 ++++++++++++++++++
xen/include/asm-x86/config.h | 8 ++++++++
2 files changed, 26 insertions(+)
diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 96ca2bf..9aa9d3f 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -89,6 +89,24 @@ config TBOOT
Technology (TXT)
If unsure, say Y.
+
+config UNSAFE_ERRPTR
+ def_bool n
+ prompt "Unsafe ERR_PTR() constants" if EXPERT = "y"
+ ---help---
+ The ERR_PTR() infrastructure by default uses the top of virtual
+ address space for error information, but with 64bit PV guests, this
+ range belongs to the guest kernel.
+
+ Xen by default slides the error range elsewhere in virtual address
+ space, but this comes at the expense of a few extra instructions of
+ calculations.
+
+ If that overhead is too much, this option is safe to enable if no
+ 64bit PV guests are in use, or all 64bit PV guests are fully trusted.
+
+ If unsure, say N.
+
endmenu
source "common/Kconfig"
diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
index 6fd84e7..2997ee3 100644
--- a/xen/include/asm-x86/config.h
+++ b/xen/include/asm-x86/config.h
@@ -87,6 +87,14 @@
#define LIST_POISON1 ((void *)0x0100100100100100UL)
#define LIST_POISON2 ((void *)0x0200200200200200UL)
+#if !defined(NDEBUG) || !defined(CONFIG_UNSAFE_ERRPTR)
+/*
+ * Always use safe pointers in debug builds. Use safe pointers in release
+ * builds unless the user explicitly opts out.
+ */
+#define ARCH_ERR_PTR_SLIDE (-(unsigned long)0xbad0eee100000000ull)
+#endif
+
#ifndef __ASSEMBLY__
extern unsigned long trampoline_phys;
#define bootsym_phys(sym) \
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-11-01 10:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-01 10:46 [PATCH for-4.9 0/3] Improvements to ERR_PTR() infrastructure Andrew Cooper
2016-11-01 10:46 ` [PATCH 1/3] xen/err: Use static inlines and boolean types Andrew Cooper
2016-11-02 11:33 ` Jan Beulich
2016-11-01 10:46 ` [PATCH 2/3] xen/err: Support an optional per-arch slide for the error region Andrew Cooper
2016-11-02 11:37 ` Jan Beulich
2016-11-01 10:46 ` Andrew Cooper [this message]
2016-11-02 11:47 ` [PATCH 3/3] xen/x86: Use non-canonical pointers for ERR_PTR() errors Jan Beulich
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=1477997170-7795-4-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).