ASAN: Implement dynamic allocas/VLAs sanitization.
authorMaxim Ostapenko <m.ostapenko@samsung.com>
Thu, 6 Jul 2017 16:02:06 +0000 (16:02 +0000)
committerMaxim Ostapenko <chefmax@gcc.gnu.org>
Thu, 6 Jul 2017 16:02:06 +0000 (19:02 +0300)
commite3174bdf35c172f69daf08350401aa177f8f1498
treee7632bf6f8c4e541f5dbf209ad90d807a7b79318
parentb6f4312871d39547c2e286b6eadac4408ab494ae
ASAN: Implement dynamic allocas/VLAs sanitization.

gcc/
* asan.c: Include gimple-fold.h.
(get_last_alloca_addr): New function.
(handle_builtin_stackrestore): Likewise.
(handle_builtin_alloca): Likewise.
(asan_emit_allocas_unpoison): Likewise.
(get_mem_refs_of_builtin_call): Add new parameter, remove const
quallifier from first paramerer. Handle BUILT_IN_ALLOCA,
BUILT_IN_ALLOCA_WITH_ALIGN and BUILT_IN_STACK_RESTORE builtins.
(instrument_builtin_call): Pass gimple iterator to
get_mem_refs_of_builtin_call.
(last_alloca_addr): New global.
* asan.h (asan_emit_allocas_unpoison): Declare.
* builtins.c (expand_asan_emit_allocas_unpoison): New function.
(expand_builtin): Handle BUILT_IN_ASAN_ALLOCAS_UNPOISON.
* cfgexpand.c (expand_used_vars): Call asan_emit_allocas_unpoison
if function calls alloca.
* gimple-fold.c (replace_call_with_value): Remove static keyword.
* gimple-fold.h (replace_call_with_value): Declare.
* internal-fn.c: Include asan.h.
* sanitizer.def (BUILT_IN_ASAN_ALLOCA_POISON,
BUILT_IN_ASAN_ALLOCAS_UNPOISON): New builtins.

gcc/testsuite/
* c-c++-common/asan/alloca_big_alignment.c: New test.
* c-c++-common/asan/alloca_detect_custom_size.c: Likewise.
* c-c++-common/asan/alloca_instruments_all_paddings.c: Likewise.
* c-c++-common/asan/alloca_loop_unpoisoning.c: Likewise.
* c-c++-common/asan/alloca_overflow_partial.c: Likewise.
* c-c++-common/asan/alloca_overflow_right.c: Likewise.
* c-c++-common/asan/alloca_safe_access.c: Likewise.
* c-c++-common/asan/alloca_underflow_left.c: Likewise.

From-SVN: r250031
18 files changed:
gcc/ChangeLog
gcc/asan.c
gcc/asan.h
gcc/builtins.c
gcc/cfgexpand.c
gcc/gimple-fold.c
gcc/gimple-fold.h
gcc/internal-fn.c
gcc/sanitizer.def
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/asan/alloca_big_alignment.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_detect_custom_size.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_instruments_all_paddings.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_overflow_partial.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_overflow_right.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_safe_access.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/alloca_underflow_left.c [new file with mode: 0644]