Skip to content

Commit

Permalink
core: asan: KASAN and ASLR are incompatible
Browse files Browse the repository at this point in the history
The address sanitizer shadow offset address is given at compile time
(CFG_ASAN_SHADOW_OFFSET) and is hard-coded by the compiler into the
prologue of instrumented functions, for the purpose of initializing
the shadow area for the stack (local variables). With ASLR turned on,
this address becomes invalid because of the random ASLR offset.

For KASAN to work with ASLR, we would need to be able to provide the
shadow offset dynamically, translating CFG_ASAN_SHADOW_OFFSET to the
proper VA including the ASLR offset. An attempt was made three years
ago to extend the GCC compiler with such a feature [1] but there was no
feedback from the maintainers [2].

Add a check in mk/config.mk so that KASAN and ASLR may not be enabled
simultaneously.

Link: https://blogs.coreboot.org/blog/2020/08/31/gsoc-address-sanitizer-wrap-up/ [1]
Link: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/550176.html [2]
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
jforissier committed Aug 25, 2023
1 parent 1983092 commit 763ac89
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mk/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ CFG_CORE_SANITIZE_UNDEFINED ?= n
# default
CFG_CORE_SANITIZE_KADDRESS ?= n

ifeq (y-y,$(CFG_CORE_SANITIZE_KADDRESS)-$(CFG_CORE_ASLR))
$(error CFG_CORE_SANITIZE_KADDRESS and CFG_CORE_ASLR are not compatible)
endif

# Add stack guards before/after stacks and periodically check them
CFG_WITH_STACK_CANARIES ?= y

Expand Down

0 comments on commit 763ac89

Please sign in to comment.