From: Andy Lutomirski <luto@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Borislav Petkov <bp@alien8.de>,
Kees Cook <keescook@chromium.org>,
Brian Gerst <brgerst@gmail.com>,
Andy Lutomirski <luto@kernel.org>
Subject: [PATCH 7/7] x86/uaccess: OOPS or warn on a fault with KERNEL_DS and !pagefault_disabled()
Date: Tue, 24 May 2016 15:48:44 -0700 [thread overview]
Message-ID: <f766e3c623fd9cf76568741e28e28d0de7d912ce.1464129798.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1464129798.git.luto@kernel.org>
In-Reply-To: <cover.1464129798.git.luto@kernel.org>
If someone calls set_fs(KERNEL_DS), then they are responsible for
making sure that whatever addresses are accessed are safe. If they
get it wrong on a kernel address, OOPS. If they get it wrong on a user
address, warn.
This will make it harder to exploit bugs in which user code controls
a pointer accessed with KERNEL_DS: an attacker will OOPS if they
access an unmapped page, and they'll therefore need luck or a kASLR
bypass in addition.
To keep probe_kernel_read(), probe_kernel_write(), and
probe_kernel_address() working, skip this check if
pagefault_disabled().
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
arch/x86/mm/extable.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 818cc7ffef79..4bf3ab2b8be1 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -60,6 +60,37 @@ static bool uaccess_fault_okay(int trapnr, unsigned long error_code,
return false;
}
+ /*
+ * If fs == KERNEL_DS, then all uaccess should be directed to
+ * known-good kernel addresses.
+ *
+ * We still need to support probe_kernel_read and
+ * probe_kernel_address, which disable page faults. This could be
+ * tightened up a bit if we explicitly annotated probe_kernel_read(),
+ * probe_kernel_write() and probe_kernel_address(), perhaps by
+ * introducing PROBE_KERNEL_DS.
+ */
+ if (unlikely(!is_user_ds && !pagefault_disabled())) {
+ if (extra < TASK_SIZE_MAX) {
+ /*
+ * Accessing user address under KERNEL_DS. This is a
+ * bug and should be fixed, but OOPSing is not helpful
+ * for exploit mitigation.
+ */
+ WARN_ONCE(1, "BUG: uaccess fault at 0x%lx with KERNEL_DS\n",
+ extra);
+ } else {
+ /*
+ * If a bug that allows user-controlled KERNEL_DS
+ * access exists, this will prevent it from being used
+ * to trivially bypass kASLR.
+ */
+ pr_crit("BUG: uaccess fault at 0x%lx with KERNEL_DS\n",
+ extra);
+ return false;
+ }
+ }
+
return true;
}
--
2.5.5
next prev parent reply other threads:[~2016-05-24 22:49 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-24 22:48 [PATCH 0/7] x86: uaccess hardening, easy part Andy Lutomirski
2016-05-24 22:48 ` [PATCH 1/7] x86/xen: Simplify set_aliased_prot Andy Lutomirski
2016-05-25 9:38 ` Andrew Cooper
2016-05-25 9:50 ` [Xen-devel] " David Vrabel
2016-06-10 22:12 ` Andy Lutomirski
2016-06-11 9:29 ` Ingo Molnar
2016-06-11 9:34 ` [tip:x86/asm] x86/xen: Simplify set_aliased_prot() tip-bot for Andy Lutomirski
2016-05-24 22:48 ` [PATCH 2/7] x86/extable: Pass error_code and an extra unsigned long to exhandlers Andy Lutomirski
2016-05-24 22:48 ` [PATCH 3/7] x86/uaccess: Give uaccess faults their own handler Andy Lutomirski
2016-05-24 22:48 ` [PATCH 4/7] x86/dumpstack: If addr_limit is non-default, display it Andy Lutomirski
2016-05-25 11:32 ` Borislav Petkov
2016-05-29 16:44 ` Andy Lutomirski
2016-05-25 11:39 ` Borislav Petkov
2016-05-29 16:47 ` Andy Lutomirski
2016-05-29 18:42 ` Boris Petkov
2016-05-29 19:08 ` Andy Lutomirski
2016-05-30 7:40 ` Borislav Petkov
2016-05-24 22:48 ` [PATCH 5/7] x86/uaccess: Warn on uaccess faults other than #PF Andy Lutomirski
2016-05-25 9:49 ` Borislav Petkov
2016-05-29 16:42 ` Andy Lutomirski
2016-05-24 22:48 ` [PATCH 6/7] x86/uaccess: Don't fix up USER_DS uaccess faults to kernel addresses Andy Lutomirski
2016-05-24 22:48 ` Andy Lutomirski [this message]
2016-05-25 15:33 ` [PATCH 7/7] x86/uaccess: OOPS or warn on a fault with KERNEL_DS and !pagefault_disabled() Borislav Petkov
2016-05-29 16:52 ` Andy Lutomirski
2016-05-25 3:55 ` [PATCH 0/7] x86: uaccess hardening, easy part Brian Gerst
2016-05-25 17:19 ` Kees Cook
2016-05-25 17:31 ` Kees Cook
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=f766e3c623fd9cf76568741e28e28d0de7d912ce.1464129798.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®