Commit Graph

122 Commits

Author SHA1 Message Date
David Majnemer 3400563ea6 UBSan: Teach isDerivedFromAtOffset and findBaseAtOffset about vbases
When the __virtual_mask is set, __offset_flags >> __offset_shift yields
an offset into the vtable.  Dereferencing this vtable slot gets us the
vbase offset.

Adjust a test case to verify that this, in fact, works.

Differential Revision: http://reviews.llvm.org/D6074

llvm-svn: 221445
2014-11-06 08:55:23 +00:00
Alexey Samsonov 70f3897b0a [Sanitizer] Introduce generic stack frame rendering machinery
Summary:
This commit introduces function __sanitizer::RenderFrame()
that allows to render the contents of AddressInfo (essentially, symbolized stack frame)
using the custom format string. This function can be used to
implement stack frame formatting for both ThreadSanitizer and
generic StackTrace::Print(), used in another places. This paves the
way towards allowing user to control the format of stack frames,
obtaining them in any format he desires, and/or enforcing the consistent
output from all sanitizers.

Test Plan: compiler-rt test suite

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6140

llvm-svn: 221409
2014-11-05 22:44:36 +00:00
Alexey Samsonov 9c85927012 [Sanitizer] Make StackTrace a lightweight reference to array of PCs, and
introduce a BufferedStackTrace class, which owns this array.

Summary:
This change splits __sanitizer::StackTrace class into a lightweight
__sanitizer::StackTrace, which doesn't own array of PCs, and BufferedStackTrace,
which owns it. This would allow us to simplify the interface of StackDepot,
and eventually merge __sanitizer::StackTrace with __tsan::StackTrace.

Test Plan: regression test suite.

Reviewers: kcc, dvyukov

Reviewed By: dvyukov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5985

llvm-svn: 220635
2014-10-26 03:35:14 +00:00
Alexey Samsonov eb47d8a2c8 Sanitize upcasts and conversion to virtual base.
This change adds UBSan check to upcasts. Namely, when we
perform derived-to-base conversion, we:
1) check that the pointer-to-derived has suitable alignment
   and underlying storage, if this pointer is non-null.
2) if vptr-sanitizer is enabled, and we perform conversion to
   virtual base, we check that pointer-to-derived has a matching vptr.

llvm-svn: 219642
2014-10-13 23:59:00 +00:00
Evgeniy Stepanov 0f7ab59adc [sanitizer] Add i686 arch to compiler-rt.
This is needed so we can produce -i686- named libraries for
x86 Android (which is i686-linux-android).

An alternative solution would be keeping the "i386" name internally and
tweaking the OUTPUT_NAME of compiler-rt libraries.

llvm-svn: 218761
2014-10-01 12:55:06 +00:00
Alexey Samsonov 7dd95610e5 UBSan: print 'undefined-behavior' instead of 'runtime-error' in report summary
llvm-svn: 218264
2014-09-22 19:39:46 +00:00
Alexey Samsonov 25c2224922 [UBSan] Introduce more flexible __ubsan_default_options function instead of UBSAN_DEFAULT_OPTIONS compile definition
llvm-svn: 218137
2014-09-19 18:54:52 +00:00
Alexey Samsonov 760750c44f [UBSan] Optionally report summary in UBSan error reports.
By default summary is not printed if UBSan is run in a standalone mode,
but is printed if it's combined with another sanitizer (like ASan).

llvm-svn: 218135
2014-09-19 18:33:45 +00:00
Alexey Samsonov 1947bf9921 PR20721: Don't let UBSan print inaccessible memory
Summary:
UBSan needs to check if memory snippet it's going to print resides
in addressable memory. Similar check might be helpful in ASan with
dump_instruction_bytes option (see http://reviews.llvm.org/D5167).

Instead of scanning /proc/self/maps manually, delegate this check to
the OS kernel: try to write this memory in a syscall and assume that
memory is inaccessible if the syscall failed (e.g. with EFAULT).

Fixes PR20721.

Test Plan: compiler-rt test suite

Reviewers: eugenis, glider

Reviewed By: glider

Subscribers: emaste, ygribov, llvm-commits, glider, rsmith

Differential Revision: http://reviews.llvm.org/D5253

llvm-svn: 217971
2014-09-17 17:56:15 +00:00
Alexey Samsonov 0e8364e912 [UBSan] Don't overflow when calculating memory range that should be dumped
llvm-svn: 217703
2014-09-12 19:51:26 +00:00
Alexey Samsonov 74f07ed7fe Revert r217616. Problems and complexity it introduces negate its benefit
llvm-svn: 217652
2014-09-12 01:26:57 +00:00
Alexey Samsonov 5d2c0dfe4c [UBSan] Parse common flags from UBSAN_OPTIONS runtime variable even if
UBSan is combined with ASan.

llvm-svn: 217616
2014-09-11 18:20:11 +00:00
Alexey Samsonov 611c906cb3 [Sanitizer] Get rid of Symbolizer::Get() and Symbolizer::GetOrNull().
We may as well just use Symbolizer::GetOrInit() in all the cases.
Don't call Symbolizer::Get() early in tools initialization: these days
it doesn't do any important setup work, and we may as well create the
symbolizer the first time it's actually needed.

llvm-svn: 217558
2014-09-10 22:45:09 +00:00
Alexey Samsonov 7f0f17b3fb [UBSan] Add noinline attribute to handlers that should never return.
FIx a problem reported by Jakub Jelinek: don't do early-exit from fatal
UBSan handlers: even if source location is disabled (i.e. acquired by
some other thread), we should continue the execution to make sure that:
a) some thread will print the error report before calling Die().
b) handler marked as noreturn will indeed not return.

Explicitly add "Die()" calls at the end of all fatal handlers to be
sure UBSan handlers don't introduce UB themselves.

llvm-svn: 217542
2014-09-10 20:43:36 +00:00
Alexey Samsonov b69d5dffc3 [UBSan] Add halt_on_error runtime flag
llvm-svn: 217535
2014-09-10 19:35:31 +00:00
Alexey Samsonov 513e8a911f Remove extra semicolon [-Wpedantic]
llvm-svn: 217407
2014-09-08 23:37:09 +00:00
Alexey Samsonov 90452df7b1 Report source location of returns_nonnull attribute in UBSan reports.
llvm-svn: 217400
2014-09-08 20:17:19 +00:00
Alexey Samsonov c7c3ae0a8b Revert accidental change
llvm-svn: 217391
2014-09-08 17:52:48 +00:00
Alexey Samsonov 8e1162c71d Implement nonnull-attribute sanitizer
Summary:
This patch implements a new UBSan check, which verifies
that function arguments declared to be nonnull with __attribute__((nonnull))
are actually nonnull in runtime.

To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs
(where applicable) and if function declaration has nonnull attribute specified
for a certain formal parameter, we compare the corresponding RValue to null as
soon as it's calculated.

Test Plan: regression test suite

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits, rnk

Differential Revision: http://reviews.llvm.org/D5082

llvm-svn: 217389
2014-09-08 17:22:45 +00:00
Alexey Samsonov 2ccbc621df [UBSan] Add support for printing backtraces to all UBSan handlers
llvm-svn: 216289
2014-08-22 21:42:04 +00:00
Alexey Samsonov de443c5002 [UBSan] Add returns-nonnull sanitizer.
Summary:
This patch adds a runtime check verifying that functions
annotated with "returns_nonnull" attribute do in fact return nonnull pointers.
It is based on suggestion by Jakub Jelinek:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140623/223693.html.

Test Plan: regression test suite

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D4849

llvm-svn: 215485
2014-08-13 00:26:40 +00:00
Alexey Samsonov ff24fd2516 [UBSan] Allow to suppress reports from vptr checker for specified types.
Based on http://reviews.llvm.org/D4702 by Byoungyoung Lee!

llvm-svn: 214833
2014-08-05 01:24:22 +00:00
Alexey Samsonov 96591cd1f1 [UBSan] Introduce ScopedReport object.
This object is used to encapsulate all actions that need to be
done before/after printing UBSan diagnostics. Currently these
actions are:
* locking a mutex to ensure that UBSan diagnostics from several
threads won't mix with each other and with other sanitizers' 
reports
* killing a program once the report is printed (if necessary).

Use this object in all UBSan handlers. Unify the way we implement
fatal and non-fatal handlers by making all the handlers simple
one-liners that redirect __ubsan_handle_foo(_abort)? to
handleFooImpl().

llvm-svn: 214279
2014-07-30 01:49:19 +00:00
Alexey Samsonov 64a5f0fa1a [UBSan] Allow to override runtime flags defaults by providing
compile definition UBSAN_DEFAULT_OPTIONS when building the runtime.
This mirrors similar ASan functionality.

llvm-svn: 214259
2014-07-30 00:01:41 +00:00
Alexey Samsonov 6ae5bac794 [UBSan] Move all runtime flags parsing to ubsan_flags.cc.
No functionality change.

llvm-svn: 214258
2014-07-29 23:49:20 +00:00
Alexey Samsonov 20c5c7b723 [UBSan] Get pc/bp for stack unwinding as early as possible.
This will ensure that stack frames in error reports will not
contain internal UBSan failures, and frame #0 will be the
actual place in the program where the error happens.

llvm-svn: 214245
2014-07-29 23:22:41 +00:00
Alexey Samsonov 17edc9230e [UBSan] Build part of UBSan runtime that can be linked into C programs with -fno-rtti flag.
llvm-svn: 214232
2014-07-29 21:52:25 +00:00
Alexey Samsonov e87e5ce5d6 [UBSan] Initialize symbolizer inside __ubsan::Init().
We used to initialize symbolizer lazily, but this doesn't work in
various sandboxed environments. Instead, let's be consistent with
the rest of sanitizers.

llvm-svn: 214006
2014-07-26 01:41:45 +00:00
Alexey Samsonov 6eb53d6460 [UBSan] Call UBSan initialization as early as possible.
Specifically, use .preinit_array initialization on Linux and dynamic global
initializer on another platforms. Historically UBSan didn't have any
initialization code and its runtime was stateless. This is no longer the
case - UBSan relies on some non-trivial functionality from sanitizer_common
(e.g. online symbolization) and is now configurable by runtime flags.
Additionally, we've dropped support for enabling UBSan only for a few shared
objects, so UBSan is now always linked into the main executable, so now
we can use similar initialization as all the rest sanitizers.

llvm-svn: 213983
2014-07-25 22:24:34 +00:00
Alexey Samsonov db615d565d Fix unused-variable warning
llvm-svn: 213786
2014-07-23 19:40:54 +00:00
Alexey Samsonov bfa711c8b0 [UBSan] Add the ability to dump call stacks to -fsanitize=vptr
This change introduces the first UBSan-specific runtime flag: print_stacktrace
(off by default). It can be set in UBSAN_OPTIONS to unwind and print call stacks
in addition to diagnostic messages. For now these stacks are printed only
in vptr checker.

This change is based on http://reviews.llvm.org/D4410 by Byoungyoung Lee!

llvm-svn: 213783
2014-07-23 18:44:54 +00:00
Alexey Samsonov cd875aa551 [UBSan] Introduce UBSAN_OPTIONS environment variable.
If UBSan is run in a standalone mode (w/o any other sanitizer), it
still uses functions from sanitizer_common, some of which depend on
the value of runtime flags. Allow to override the default values of these
flags with UBSAN_OPTIONS variable. In particular, UBSAN_OPTIONS=symbolize=0
can be used to turn off online symbolization.

llvm-svn: 213782
2014-07-23 18:32:55 +00:00
Alexey Samsonov e287ef847a [Sanitizer] Merge AnsiColorDecorator and SanitizerCommonDecorator, use the latter in UBSan
llvm-svn: 210959
2014-06-13 23:46:37 +00:00
Alexey Samsonov 3e61c52352 [UBSan] Respect runtime flag for colorizing reports
llvm-svn: 210950
2014-06-13 22:48:40 +00:00
Kostya Serebryany a72efdff9e [ubsan] handle long double in 32-bit mode; part of the patch by Marek Polacek
llvm-svn: 209516
2014-05-23 14:45:13 +00:00
Alexey Samsonov 78a8435fd6 [CMake] Rename add_compiler_rt_static_runtime to add_compiler_rt_runtime.
Soon there will be an option to build compiler-rt parts as shared libraries
on Linux. Extracted from http://llvm-reviews.chandlerc.com/D3042
by Yuri Gribov.

llvm-svn: 205183
2014-03-31 13:45:36 +00:00
Alexey Samsonov 97c22f79e1 Enable UBSan on FreeBSD. Patch by Viktor Kutuzov.
llvm-svn: 202122
2014-02-25 08:29:36 +00:00
Alexey Samsonov 63a4af7346 [CMake] Add top-level target for each compiler-rt library, and add 'compiler-rt' target encompassing them all.
llvm-svn: 201556
2014-02-18 09:33:45 +00:00
Alexey Samsonov ba869e79a0 Move UBSan test suite under test/
llvm-svn: 201401
2014-02-14 11:42:22 +00:00
Alexey Samsonov 81a2b466e9 Move shared configs for lit test suites to test/ and unittests/ directories
llvm-svn: 201399
2014-02-14 11:00:07 +00:00
Alexey Samsonov c34a997669 [UBSan] Parse common runtime flags before using a symbolizer
llvm-svn: 201217
2014-02-12 08:21:44 +00:00
Alexey Samsonov c496eba75f Don't create check-ubsan and check-dfsan commands if they are not supported on this platform
llvm-svn: 199979
2014-01-24 08:06:21 +00:00
Timur Iskhodzhanov b5f983e4b0 [Sanitizers] Rename Symbolizer::SymbolizeCode to Symbolizer::SymbolizePC
llvm-svn: 197569
2013-12-18 14:17:39 +00:00
Will Dietz 3177a7f38a ubsan: Fix typo in 'TypeCheck/vptr.cpp' test to resolve 32bit failure.
llvm-svn: 196799
2013-12-09 19:04:33 +00:00
Will Dietz 186507dac6 Fix integer tests on platforms where uint64_t is 'unsigned long long'.
llvm-svn: 196612
2013-12-06 21:49:18 +00:00
Alexey Samsonov c700e76278 [UBSan] Fix warning by specifying __extension__ before __int128
llvm-svn: 195648
2013-11-25 15:12:40 +00:00
Alexey Samsonov 164841036d [UBSan] Make sure ASan and UBSan interact properly by running each test from UBSan test suite with and without ASan
llvm-svn: 194698
2013-11-14 12:30:09 +00:00
Alexey Samsonov 84dbdc0d8e [UBSan] Update UBSan location rendering to match r194686
llvm-svn: 194687
2013-11-14 09:54:10 +00:00
Peter Collingbourne 791e65dcfb Overhaul the symbolizer interface.
This moves away from creating the symbolizer object and initializing the
external symbolizer as separate steps.  Those steps now always take place
together.

Sanitizers with a legacy requirement to specify their own symbolizer path
should use InitSymbolizer to initialize the symbolizer with the desired
path, and GetSymbolizer to access the symbolizer.  Sanitizers with no
such requirement (e.g. UBSan) can use GetOrInitSymbolizer with no need for
initialization.

The symbolizer interface has been made thread-safe (as far as I can
tell) by protecting its member functions with mutexes.

Finally, the symbolizer interface no longer relies on weak externals, the
introduction of which was probably a mistake on my part.

Differential Revision: http://llvm-reviews.chandlerc.com/D1985

llvm-svn: 193448
2013-10-25 23:03:29 +00:00
Peter Collingbourne 90a0876ae7 Runtime support for the indirect function call checker.
Differential Revision: http://llvm-reviews.chandlerc.com/D1339

llvm-svn: 193060
2013-10-20 21:29:46 +00:00