[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-bef459026b161fbc39d20dcba698ed0cfffbac38@git.kernel.org>
Date: Mon, 3 Sep 2018 06:19:12 -0700
From: tip-bot for Jann Horn <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, keescook@...omium.org,
mhiramat@...nel.org, tglx@...utronix.de,
naveen.n.rao@...ux.vnet.ibm.com, mingo@...nel.org, luto@...nel.org,
hpa@...or.com, jannh@...gle.com, davem@...emloft.net, bp@...en8.de,
anil.s.keshavamurthy@...el.com, viro@...iv.linux.org.uk
Subject: [tip:x86/core] lkdtm: Test copy_to_user() on bad kernel pointer
under KERNEL_DS
Commit-ID: bef459026b161fbc39d20dcba698ed0cfffbac38
Gitweb: https://git.kernel.org/tip/bef459026b161fbc39d20dcba698ed0cfffbac38
Author: Jann Horn <jannh@...gle.com>
AuthorDate: Tue, 28 Aug 2018 22:14:21 +0200
Committer: Thomas Gleixner <tglx@...utronix.de>
CommitDate: Mon, 3 Sep 2018 15:12:10 +0200
lkdtm: Test copy_to_user() on bad kernel pointer under KERNEL_DS
Test whether the kernel WARN()s when, under KERNEL_DS, a bad kernel pointer
is used as "userspace" pointer. Should normally be used in "DIRECT" mode.
Signed-off-by: Jann Horn <jannh@...gle.com>
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Tested-by: Kees Cook <keescook@...omium.org>
Acked-by: Kees Cook <keescook@...omium.org>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: kernel-hardening@...ts.openwall.com
Cc: dvyukov@...gle.com
Cc: Masami Hiramatsu <mhiramat@...nel.org>
Cc: "Naveen N. Rao" <naveen.n.rao@...ux.vnet.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@...el.com>
Cc: "David S. Miller" <davem@...emloft.net>
Cc: Alexander Viro <viro@...iv.linux.org.uk>
Cc: linux-fsdevel@...r.kernel.org
Cc: Borislav Petkov <bp@...en8.de>
Link: https://lkml.kernel.org/r/20180828201421.157735-8-jannh@google.com
---
drivers/misc/lkdtm/core.c | 1 +
drivers/misc/lkdtm/lkdtm.h | 1 +
drivers/misc/lkdtm/usercopy.c | 13 +++++++++++++
3 files changed, 15 insertions(+)
diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
index 2154d1bfd18b..5a755590d3dc 100644
--- a/drivers/misc/lkdtm/core.c
+++ b/drivers/misc/lkdtm/core.c
@@ -183,6 +183,7 @@ static const struct crashtype crashtypes[] = {
CRASHTYPE(USERCOPY_STACK_FRAME_FROM),
CRASHTYPE(USERCOPY_STACK_BEYOND),
CRASHTYPE(USERCOPY_KERNEL),
+ CRASHTYPE(USERCOPY_KERNEL_DS),
};
diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h
index 9e513dcfd809..07db641d71d0 100644
--- a/drivers/misc/lkdtm/lkdtm.h
+++ b/drivers/misc/lkdtm/lkdtm.h
@@ -82,5 +82,6 @@ void lkdtm_USERCOPY_STACK_FRAME_TO(void);
void lkdtm_USERCOPY_STACK_FRAME_FROM(void);
void lkdtm_USERCOPY_STACK_BEYOND(void);
void lkdtm_USERCOPY_KERNEL(void);
+void lkdtm_USERCOPY_KERNEL_DS(void);
#endif
diff --git a/drivers/misc/lkdtm/usercopy.c b/drivers/misc/lkdtm/usercopy.c
index 9725aed305bb..389475b25bb7 100644
--- a/drivers/misc/lkdtm/usercopy.c
+++ b/drivers/misc/lkdtm/usercopy.c
@@ -322,6 +322,19 @@ free_user:
vm_munmap(user_addr, PAGE_SIZE);
}
+void lkdtm_USERCOPY_KERNEL_DS(void)
+{
+ char __user *user_ptr = (char __user *)ERR_PTR(-EINVAL);
+ mm_segment_t old_fs = get_fs();
+ char buf[10] = {0};
+
+ pr_info("attempting copy_to_user on unmapped kernel address\n");
+ set_fs(KERNEL_DS);
+ if (copy_to_user(user_ptr, buf, sizeof(buf)))
+ pr_info("copy_to_user un unmapped kernel address failed\n");
+ set_fs(old_fs);
+}
+
void __init lkdtm_usercopy_init(void)
{
/* Prepare cache that lacks SLAB_USERCOPY flag. */
Powered by blists - more mailing lists