[PATCH] D81390: [KernelAddressSanitizer] Make globals constructors compatible with kernel

Marco Elver via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 07:05:29 PDT 2020


melver created this revision.
melver added a reviewer: glider.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, aprantl.
Herald added a reviewer: aaron.ballman.
Herald added projects: clang, LLVM.

[ The first version of this feature was reverted due to modpost causing

  failures. This version fixes this. More info:
  https://github.com/ClangBuiltLinux/linux/issues/1045#issuecomment-640381783 ]

This makes -fsanitize=kernel-address emit the correct globals
constructors for the kernel. We had to do the following:

- Disable generation of constructors that rely on linker features such as dead-global elimination.

- Only instrument globals *not* in explicit sections. The kernel uses sections for special globals, which we should not touch.

- Do not instrument globals that are aliased by a symbol that is prefixed with "__". For example, modpost relies on specially named aliases to find globals and checks their contents. Unfortunately mod post relies on size stored as ELF debug info and any padding of globals currently causes the debug info to cause size reported to be *with* redzone which throws modpost off.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203493

Tested:

1. With 'clang/test/CodeGen/asan-globals.cpp'.

2. With test_kasan.ko, we can see:

  	BUG: KASAN: global-out-of-bounds in kasan_global_oob+0xb3/0xba [test_kasan]

3. allyesconfig, allmodconfig


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81390

Files:
  clang/test/CodeGen/asan-globals.cpp
  llvm/include/llvm/Transforms/Utils/ModuleUtils.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Utils/ModuleUtils.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81390.269211.patch
Type: text/x-patch
Size: 15959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200608/6428cfa4/attachment-0001.bin>


More information about the llvm-commits mailing list