[Sanitizers] ASan: detect new/delete calls with mismatched alignment.
authorAlex Shlyapnikov <alekseys@google.com>
Wed, 25 Oct 2017 17:21:37 +0000 (17:21 +0000)
committerAlex Shlyapnikov <alekseys@google.com>
Wed, 25 Oct 2017 17:21:37 +0000 (17:21 +0000)
commita53b55f66ca46597294005fec276359ab7c37018
treea147b52bd6bbdb90c676f6d0965beea7baa5eebe
parent6391458e9c52e3cf287fcd44a57c5752b47f1613
[Sanitizers] ASan: detect new/delete calls with mismatched alignment.

ASan allocator stores the requested alignment for new and new[] calls
and on delete and delete[] verifies that alignments do match.

The representable alignments are: default alignment, 8, 16, 32, 64, 128,
256 and 512 bytes. Alignments > 512 are stored as 512, hence two
different alignments > 512 will pass the check (possibly masking the bug),
but limited memory requirements deemed to be a resonable tradeoff for
relaxed conditions.

The feature is controlled by new_delete_type_mismatch flag, the same one
protecting new/delete matching size check.

Differential revision: https://reviews.llvm.org/D38574

Issue: https://github.com/google/sanitizers/issues/799
llvm-svn: 316595
compiler-rt/lib/asan/asan_allocator.cc
compiler-rt/lib/asan/asan_allocator.h
compiler-rt/lib/asan/asan_descriptions.cc
compiler-rt/lib/asan/asan_descriptions.h
compiler-rt/lib/asan/asan_errors.cc
compiler-rt/lib/asan/asan_errors.h
compiler-rt/lib/asan/asan_new_delete.cc
compiler-rt/lib/asan/asan_report.cc
compiler-rt/lib/asan/asan_report.h
compiler-rt/test/asan/TestCases/Linux/aligned_delete_test.cc [new file with mode: 0644]