OrangePi_CM5/drivers/misc/lkdtm
Marco Elver 941faf832d UPSTREAM: lkdtm: disable KASAN for rodata.o
[ Upstream commit 6d5a88cd0c1506115d71a4d3a26b60645c89df6c ]

Building lkdtm with KASAN and Clang 11 or later results in the following
error when attempting to load the module:

  kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
  BUG: unable to handle page fault for address: ffffffffc019cd70
  #PF: supervisor instruction fetch in kernel mode
  #PF: error_code(0x0011) - permissions violation
  ...
  RIP: 0010:asan.module_ctor+0x0/0xffffffffffffa290 [lkdtm]
  ...
  Call Trace:
   do_init_module+0x17c/0x570
   load_module+0xadee/0xd0b0
   __x64_sys_finit_module+0x16c/0x1a0
   do_syscall_64+0x34/0x50
   entry_SYSCALL_64_after_hwframe+0x44/0xa9

The reason is that rodata.o generates a dummy function that lives in
.rodata to validate that .rodata can't be executed; however, Clang 11 adds
KASAN globals support by generating module constructors to initialize
globals redzones.  When Clang 11 adds a module constructor to rodata.o, it
is also added to .rodata: any attempt to call it on initialization results
in the above error.

Therefore, disable KASAN instrumentation for rodata.o.

Link: https://lkml.kernel.org/r/20201214191413.3164796-1-elver@google.com
Signed-off-by: Marco Elver <elver@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Bug: 172318110
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Change-Id: I0a3662322bac8961b0f87ab5e8e87acfb1ac3ec5
2021-01-19 21:47:27 -08:00
..
Makefile UPSTREAM: lkdtm: disable KASAN for rodata.o 2021-01-19 21:47:27 -08:00
bugs.c Revert "Revert "lkdtm: remove set_fs-based tests"" 2020-10-28 15:08:42 +01:00
cfi.c lkdtm: Add Control Flow Integrity test 2019-08-12 15:28:51 -07:00
core.c Revert "Revert "lkdtm: remove set_fs-based tests"" 2020-10-28 15:08:42 +01:00
heap.c lkdtm/heap: Avoid edge and middle of slabs 2020-06-29 18:41:39 +02:00
lkdtm.h Revert "Revert "lkdtm: remove set_fs-based tests"" 2020-10-28 15:08:42 +01:00
perms.c lkdtm: Avoid more compiler optimizations for bad writes 2020-06-29 18:41:39 +02:00
refcount.c lkdtm: Remove references to CONFIG_REFCOUNT_FULL 2019-11-25 09:15:46 +01:00
rodata.c
…
stackleak.c lkdtm/stackleak: Make the test more verbose 2020-02-10 13:43:38 -08:00
usercopy.c ANDROID: lkdtm: use __va_function 2021-01-14 16:33:01 +00:00