lkdtm: Add tests for NULL pointer dereference
authorChristophe Leroy <christophe.leroy@c-s.fr>
Fri, 14 Dec 2018 15:26:20 +0000 (15:26 +0000)
committerKees Cook <keescook@chromium.org>
Wed, 9 Jan 2019 20:00:31 +0000 (12:00 -0800)
Introduce lkdtm tests for NULL pointer dereference: check access or exec
at NULL address, since these errors tend to be reported differently from
the general fault error text. For example from x86:

    pr_alert("BUG: unable to handle kernel %s at %px\n",
        address < PAGE_SIZE ? "NULL pointer dereference" : "paging request",
        (void *)address);

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Kees Cook <keescook@chromium.org>
drivers/misc/lkdtm/core.c
drivers/misc/lkdtm/lkdtm.h
drivers/misc/lkdtm/perms.c

index 5d41c2230d2e47de8711a71b4f31c76860876f40..c09133ac9803cfa2282c71f4bba5f20f058cd975 100644 (file)
@@ -143,7 +143,9 @@ static const struct crashtype crashtypes[] = {
        CRASHTYPE(EXEC_VMALLOC),
        CRASHTYPE(EXEC_RODATA),
        CRASHTYPE(EXEC_USERSPACE),
+       CRASHTYPE(EXEC_NULL),
        CRASHTYPE(ACCESS_USERSPACE),
+       CRASHTYPE(ACCESS_NULL),
        CRASHTYPE(WRITE_RO),
        CRASHTYPE(WRITE_RO_AFTER_INIT),
        CRASHTYPE(WRITE_KERN),
index 3c6fd327e166a4c83dfef10f8d83209cd4f6f892..b69ee004a3f71b09e813d01565747e7ac23d6349 100644 (file)
@@ -45,7 +45,9 @@ void lkdtm_EXEC_KMALLOC(void);
 void lkdtm_EXEC_VMALLOC(void);
 void lkdtm_EXEC_RODATA(void);
 void lkdtm_EXEC_USERSPACE(void);
+void lkdtm_EXEC_NULL(void);
 void lkdtm_ACCESS_USERSPACE(void);
+void lkdtm_ACCESS_NULL(void);
 
 /* lkdtm_refcount.c */
 void lkdtm_REFCOUNT_INC_OVERFLOW(void);
index fa54add6375a023063690327d1b6078f7e488cf2..62f76d506f0405443eeb1804b220e803339d9378 100644 (file)
@@ -164,6 +164,11 @@ void lkdtm_EXEC_USERSPACE(void)
        vm_munmap(user_addr, PAGE_SIZE);
 }
 
+void lkdtm_EXEC_NULL(void)
+{
+       execute_location(NULL, CODE_AS_IS);
+}
+
 void lkdtm_ACCESS_USERSPACE(void)
 {
        unsigned long user_addr, tmp = 0;
@@ -195,6 +200,19 @@ void lkdtm_ACCESS_USERSPACE(void)
        vm_munmap(user_addr, PAGE_SIZE);
 }
 
+void lkdtm_ACCESS_NULL(void)
+{
+       unsigned long tmp;
+       unsigned long *ptr = (unsigned long *)NULL;
+
+       pr_info("attempting bad read at %px\n", ptr);
+       tmp = *ptr;
+       tmp += 0xc0dec0de;
+
+       pr_info("attempting bad write at %px\n", ptr);
+       *ptr = tmp;
+}
+
 void __init lkdtm_perms_init(void)
 {
        /* Make sure we can write to __ro_after_init values during __init */