All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/3] SROP Mitigation: Architecture independent code for signal cookies
@ 2016-03-08 20:47 ` Scott Bauer
  0 siblings, 0 replies; 36+ messages in thread
From: Scott Bauer @ 2016-03-08 20:47 UTC (permalink / raw)
  To: sbauer, linux-kernel
  Cc: kernel-hardening, x86, wmealing, ak, luto, Abhiram Balasubramanian

This patch adds a per-process secret to the task struct which
will be used during signal delivery and during a sigreturn.
Also, logic is added in signal.c to generate, place, extract,
clear and verify the signal cookie.

Cc: Abhiram Balasubramanian <abhiram@cs.utah.edu>
Signed-off-by: Scott Bauer <sbauer@eng.utah.edu>
---
 fs/exec.c              |  3 +++
 include/linux/sched.h  |  7 +++++++
 include/linux/signal.h |  2 ++
 kernel/signal.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/fs/exec.c b/fs/exec.c
index dcd4ac7..3de0a32 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -56,6 +56,7 @@
 #include <linux/pipe_fs_i.h>
 #include <linux/oom.h>
 #include <linux/compat.h>
+#include <linux/random.h>
 
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -1135,6 +1136,8 @@ void setup_new_exec(struct linux_binprm * bprm)
 	/* This is the point of no return */
 	current->sas_ss_sp = current->sas_ss_size = 0;
 
+	get_random_bytes(&current->sig_cookie, sizeof(current->sig_cookie));
+
 	if (uid_eq(current_euid(), current_uid()) && gid_eq(current_egid(), current_gid()))
 		set_dumpable(current->mm, SUID_DUMP_USER);
 	else
diff --git a/include/linux/sched.h b/include/linux/sched.h
index a10494a..556162f 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1497,6 +1497,13 @@ struct task_struct {
 	unsigned long stack_canary;
 #endif
 	/*
+	 * Canary value for signal frames placed on user stack.
+	 * This helps mitigate "Signal Return oriented program"
+	 * exploits in userland.
+	 */
+	unsigned long sig_cookie;
+
+	/*
 	 * pointers to (original) parent process, youngest child, younger sibling,
 	 * older sibling, respectively.  (p->father can be replaced with
 	 * p->real_parent->pid)
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 92557bb..fae0618 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -280,6 +280,8 @@ extern int get_signal(struct ksignal *ksig);
 extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping);
 extern void exit_signals(struct task_struct *tsk);
 extern void kernel_sigaction(int, __sighandler_t);
+extern int set_sigcookie(unsigned long __user *location);
+extern int verify_clear_sigcookie(unsigned long __user *sig_cookie_ptr);
 
 static inline void allow_signal(int sig)
 {
diff --git a/kernel/signal.c b/kernel/signal.c
index 0508544..00e4a16 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2430,6 +2430,46 @@ out:
 	}
 }
 
+static unsigned long gen_sigcookie(unsigned long __user *location)
+{
+
+	unsigned long sig_cookie;
+	sig_cookie = (unsigned long) location ^ current->sig_cookie;
+
+	return sig_cookie;
+}
+
+int set_sigcookie(unsigned long __user *location)
+{
+
+	unsigned long sig_cookie = gen_sigcookie(location);
+
+	return put_user(sig_cookie, location);
+}
+
+int verify_clear_sigcookie(unsigned long __user *sig_cookie_ptr)
+{
+	unsigned long user_cookie;
+	unsigned long calculated_cookie;
+
+	if (get_user(user_cookie, sig_cookie_ptr))
+		return 1;
+
+	calculated_cookie = gen_sigcookie(sig_cookie_ptr);
+
+	if (user_cookie != calculated_cookie) {
+		pr_warn("Signal protector does not match what kernel set it to"\
+			". Possible exploit attempt or buggy program!\n");
+		return 1;
+
+	}
+
+	user_cookie = 0;
+	return put_user(user_cookie, sig_cookie_ptr)
+}
+
+EXPORT_SYMBOL(verify_clear_sigcookie);
+EXPORT_SYMBOL(set_sigcookie);
 EXPORT_SYMBOL(recalc_sigpending);
 EXPORT_SYMBOL_GPL(dequeue_signal);
 EXPORT_SYMBOL(flush_signals);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2016-03-10  9:43 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-08 20:47 [PATCH v3 1/3] SROP Mitigation: Architecture independent code for signal cookies Scott Bauer
2016-03-08 20:47 ` [kernel-hardening] " Scott Bauer
2016-03-08 20:47 ` [PATCH v3 2/3] x86: SROP mitigation: implement " Scott Bauer
2016-03-08 20:47   ` [kernel-hardening] " Scott Bauer
2016-03-08 21:03   ` One Thousand Gnomes
2016-03-08 21:03     ` [kernel-hardening] " One Thousand Gnomes
2016-03-08 21:38     ` Scotty Bauer
2016-03-08 21:38       ` [kernel-hardening] " Scotty Bauer
2016-03-08 20:47 ` [PATCH v3 3/3] SROP mitigation: Add sysctl to disable SROP protection Scott Bauer
2016-03-08 20:47   ` [kernel-hardening] " Scott Bauer
2016-03-08 21:00   ` One Thousand Gnomes
2016-03-08 21:00     ` [kernel-hardening] " One Thousand Gnomes
2016-03-10  6:36     ` Kees Cook
2016-03-10  6:36       ` Kees Cook
2016-03-10  6:46       ` Andy Lutomirski
2016-03-10  6:46         ` Andy Lutomirski
2016-03-08 20:58 ` [PATCH v3 1/3] SROP Mitigation: Architecture independent code for signal cookies Andy Lutomirski
2016-03-08 20:58   ` [kernel-hardening] " Andy Lutomirski
2016-03-08 21:49   ` Scotty Bauer
2016-03-08 21:49     ` [kernel-hardening] " Scotty Bauer
2016-03-08 21:57     ` Andy Lutomirski
2016-03-08 21:57       ` [kernel-hardening] " Andy Lutomirski
2016-03-08 22:06       ` Scotty Bauer
2016-03-08 22:06         ` [kernel-hardening] " Scotty Bauer
2016-03-09 22:02       ` Scotty Bauer
2016-03-09 22:02         ` [kernel-hardening] " Scotty Bauer
2016-03-08 21:04 ` kbuild test robot
2016-03-08 21:04   ` [kernel-hardening] " kbuild test robot
2016-03-09  8:32 ` Ingo Molnar
2016-03-09  8:32   ` [kernel-hardening] " Ingo Molnar
2016-03-09 22:07   ` Scotty Bauer
2016-03-09 22:07     ` [kernel-hardening] " Scotty Bauer
2016-03-09 22:22     ` Jonathan Corbet
2016-03-09 22:22       ` [kernel-hardening] " Jonathan Corbet
2016-03-10  9:43       ` Ingo Molnar
2016-03-10  9:43         ` [kernel-hardening] " Ingo Molnar

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.