Commit Graph

10996 Commits

Author SHA1 Message Date
Martin Storsjö 18e06e3e2f [sanitizers] Fix building on 32 bit Windows after 7256c05ecb
On 32 bit, 'long' (which is 32 bit on Windows) is used as base
type for SIZE_T and similar.

Differential Revision: https://reviews.llvm.org/D108191
2021-08-17 21:36:09 +03:00
Marco Elver f3b3c964c3 Revert "[tsan] Fix GCC 8.3 build after D107911"
This reverts commit 797fe59e6b.

The use of "EventType type : 3" is replicated for all Event structs and
therefore was still present. As a result this still caused failures on
older GCCs (9.2 or 8.3 or earlier).

The particular bot that was failing due to buggy GCC was fixed by
fef39cc472.

Therefore, no reason to keep the workaround around; revert it.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108192
2021-08-17 19:26:20 +02:00
Peter Collingbourne affb132ab8 hwasan: Move stack ring buffer initialization before InitStackAndTls.
D104248 moved the call to GetThreadStackAndTls to before the
initialization of the ring buffer TLS slot. As a result, if libc
is instrumented we crash in pthread_getattr_np which is called from
__sanitizer::GetThreadStackTopAndBottom.

Fix the problem by moving the stack ring buffer initialization before
the call to InitStackAndTls.

Differential Revision: https://reviews.llvm.org/D108184
2021-08-17 10:18:07 -07:00
Kostya Kortchinsky 5009be2f09 [scudo] Fix format string specifiers
Enable `-Wformat` again, and fix the offending instances.

Differential Revision: https://reviews.llvm.org/D108168
2021-08-17 08:37:49 -07:00
Marco Elver d2b574a4de tsan: test: Initialize all fields of Params struct
Some compilers started complaining about the test:

	tsan_trace_test.cpp:128:21: error: missing field 'type' initializer

Fix it by initializing all 5 fields, even though the type field will be
reset in the for loop.

Differential Revision: https://reviews.llvm.org/D108207
2021-08-17 16:58:00 +02:00
Douglas Yung fef39cc472 [tsan] Another attempt to fix GCC 8.3 build after D107911
This removes the -Werror compilation flag for x64 linux to work around a gcc bug.

GCC 8.3 reports '__tsan::v3::Event::type’ is too small to hold all values of ‘enum class __tsan::v3::EventType’
incorrectly which gets promoted to an error and causes the build to fail.
2021-08-16 17:01:57 -07:00
Vitaly Buka 797fe59e6b [tsan] Fix GCC 8.3 build after D107911
gcc 8.3 reports:
__tsan::v3::Event::type’ is too small to hold all values of ‘enum class __tsan::v3::EventType’
2021-08-16 16:18:42 -07:00
Vitaly Buka 7256c05ecb [sanitizer] Define 32bit uptr as uint
This makes it consistent with uintptr_t.

It's 45138f788c with Darwin fix.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D108163
2021-08-16 15:46:37 -07:00
Vitaly Buka 3a05af12b3 Revert "[sanitizer] Fix MAC build after D108163"
They still fail to fix Darwin builds
https://green.lab.llvm.org/green/job/clang-stage1-RA/23399/consoleFull#462858634a1ca8a51-895e-46c6-af87-ce24fa4cd561

This reverts commit ae0628f716.
This reverts commit 2c6448cdc2.
2021-08-16 15:46:37 -07:00
Vitaly Buka ae0628f716 [sanitizer] Fix MAC build after D108163 2021-08-16 15:22:55 -07:00
Kostya Kortchinsky b2aaafb837 [scudo] Use stdint types for internal types (redo)
This is a redo of D108089 that broke some 32-bit builds.

`scudo::uptr` was defined as an `unsigned long` on 32-b platform,
while a `uintptr_t` is usually defined as an `unsigned int`.
This worked, this was not consistent, particularly with regard to
format string specifiers.

As suggested by Vitaly, since we are including `stdint.h`, define
the internal scudo integer types to those.

Differential Revision: https://reviews.llvm.org/D108152
2021-08-16 14:46:42 -07:00
Vitaly Buka 2c6448cdc2 [sanitizer] Define 32bit uptr as uint
This makes it consistent with uintptr_t.

It's 45138f788c with Darwin fix.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D108163
2021-08-16 14:23:45 -07:00
Gulfem Savrun Yeniceri 6c0e6f91d7 [profile] Add static keyword to binary id functions
This patch adds static keyword to internal functions that write
binary id to restrict visibility to the file that they are declared.

Differential Revision: https://reviews.llvm.org/D108154
2021-08-16 19:36:47 +00:00
Kostya Kortchinsky 427c9aa7c4 Revert "[scudo] Use stdint types for internal scudo types"
This reverts commit 5fc841d8a2.
2021-08-16 11:13:48 -07:00
Kostya Kortchinsky 5fc841d8a2 [scudo] Use stdint types for internal scudo types
`scudo::uptr` was defined as an `unsigned long` on 32-b platform,
while a `uintptr_t` is usually defined as an `unsigned int`.
This worked, this was not consistent, particularly with regard to
format string specifiers.

As suggested by Vitaly, since we are including `stdint.h`, define
the internal `scudo` integer types to those.

Differential Revision: https://reviews.llvm.org/D108089
2021-08-16 10:52:56 -07:00
Nikita Popov 4cfb047d6a [profile] Don't use pragma comment linker on mingw
At least when compiling with gcc, this is not supported and will
result in errors when linking against the profiler runtime. Only
use the pragma comment linker based code with MSVC, but not with
a mingw toolchain. This also undoes D107620, which shouldn't be
relevant anymore.

Differential Revision: https://reviews.llvm.org/D108095
2021-08-16 18:20:32 +02:00
Dmitry Vyukov 79aed89ea3 tsan: fix unused var warnings in a test
Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D108118
2021-08-16 13:13:23 +02:00
Dmitry Vyukov c97318996f tsan: add new trace
Add structures for the new trace format,
functions that serialize and add events to the trace
and trace replaying logic.

Differential Revision: https://reviews.llvm.org/D107911
2021-08-16 10:24:11 +02:00
Florian Hahn f7347dfa03
Revert "[sanitizer] Define 32bit uptr as uint"
This reverts commit 45138f788c.

It looks like this breaks building sanitizers on Darwin platforms on
Green Dragon

https://green.lab.llvm.org/green/job/clang-stage1-RA/23332/console

    FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.ios.dir/sanitizer_stacktrace.cpp.o
    /Users/buildslave/jenkins/workspace/clang-stage1-RA@2/clang-build/./bin/clang++  -DHAVE_RPC_XDR_H=0 -I/Users/buildslave/jenkins/workspace/clang-stage1-RA@2/llvm-project/compiler-rt/lib/sanitizer_common/.. -Wall -std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG -arch armv7 -arch armv7s -arch arm64 -arch armv7k -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk    -stdlib=libc++ -miphoneos-version-min=9.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk -fPIC -fno-builtin -fno-exceptions -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -g -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-format-pedantic -nostdinc++ -Wno-format -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 -MD -MT lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.ios.dir/sanitizer_stacktrace.cpp.o -MF lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.ios.dir/sanitizer_stacktrace.cpp.o.d -o lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.ios.dir/sanitizer_stacktrace.cpp.o -c '/Users/buildslave/jenkins/workspace/clang-stage1-RA@2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp'
    In file included from /Users/buildslave/jenkins/workspace/clang-stage1-RA@2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp:13:
    In file included from /Users/buildslave/jenkins/workspace/clang-stage1-RA@2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h:15:
    /Users/buildslave/jenkins/workspace/clang-stage1-RA@2/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common.h:1068:14: error: 'operator new' takes type size_t ('unsigned long') as first parameter
    inline void *operator new(__sanitizer::operator_new_size_type size,
                 ^
    1 error generated.
2021-08-16 09:08:24 +01:00
Dmitry Vyukov 7185007735 sanitizer_common: fix format string in LibIgnore
uptr should be printed with %zu.

Differential Revision: https://reviews.llvm.org/D108106
2021-08-16 09:45:42 +02:00
Vitaly Buka db0af393f9 [msan] Fix ppc64 format warning 2021-08-14 18:43:24 -07:00
Vitaly Buka 6934ab5f40 [sanitizer] Improve VSNPrintf internal diagnostics 2021-08-14 18:34:26 -07:00
Dmitry Vyukov d4d2b0c682 sanitizer_common: support %l in format strings
Currently we only support %z and %ll width modifiers,
but surprisingly not %l. This makes it impossible to print longs
(sizeof(long) not necessary equal to sizeof(size_t)).
We had some printf's that printed longs with %zu,
but that's wrong and now with __attribute__((format)) in place
they are flagged by compiler. So we either have a choice of
doing static_cast<uptr>(long) everywhere or add %l.
Adding %l looks better, that's a standard modifier.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108066
2021-08-14 17:57:40 -07:00
Vitaly Buka 45138f788c [sanitizer] Define 32bit uptr as uint
This makes it consistent with uintptr_t.
2021-08-14 16:53:46 -07:00
Vitaly Buka 1a0076db69 [sanitizer] Fix format string 2021-08-14 16:53:46 -07:00
Florian Mayer b0716269ba [sanitizer_common] disable format errors.
This broke https://lab.llvm.org/buildbot/#/builders/37/builds/6061/steps/32/logs/stdio

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D108042
2021-08-13 17:52:24 +01:00
Dmitry Vyukov 54ed8b9317 tsan/dd: fix format strings
Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D108040
2021-08-13 17:45:29 +02:00
Dmitry Vyukov ef2ff556a2 tsan: fix latent bug in shadow computation
We use kShadowCnt (number of shadow cells per application granule)
when computing shadow, but it's wrong. We need the ratio
between shadow and app memory (how much shadow is larger than app memory),
which is kShadowMultiplier.
Currently both are equal to 4, so it works fine.
Use the correct constant.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D108033
2021-08-13 16:38:56 +02:00
Dmitry Vyukov 1fbe5fb81c scudo/standalone: prepare for enabling format string checking
Move __attribute__((format)) to the function declarations in the header file.
It's almost pointless in the source file.
But disable the warning  with -Wno-format for now
since there is a number of existing warnings.

Depends on D107984.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108014
2021-08-13 13:45:30 +02:00
Dmitry Vyukov 73710858b0 ubsan: fix few format string bugs
This fixes just a few of the warnings.
Ubsan is not completely clean yet,
but these somehow pop up while I was
fixing other sanitizers.

Depends on D107983.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107984
2021-08-13 13:45:23 +02:00
Dmitry Vyukov c90bf3ff92 tsan: clean up and enable format string checking
Depends on D107982.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107983
2021-08-13 13:45:15 +02:00
Dmitry Vyukov d26d5a0a3d msan: clean up and enable format string checking
Depends on D107981.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107982
2021-08-13 13:45:02 +02:00
Dmitry Vyukov 123c58ea26 sanitizer_common: enable format string checking
Enable -Wformat in sanitizer_common now that it's
cleaned up from existing warnings.
But disable it in all sanitizers for now since
they are not cleaned up yet, but inherit sanitizer_common CFLAGS.

Depends on D107980.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107981
2021-08-13 13:44:52 +02:00
Dmitry Vyukov 4a91bbcc93 sanitizer_common: fix format strings
Fix existing -Wformat warnings.

Depends on D107979.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107980
2021-08-13 13:44:41 +02:00
Dmitry Vyukov ef6e1945af sanitizer_common: declare vars more locally in VSNPrintf
No point in declaring variables separately before use.

Depends on D107979.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108015
2021-08-13 13:44:31 +02:00
Dmitry Vyukov 2a63edd64f Revert "sanitizer_common: support printing __m128i type"
This reverts commits
"sanitizer_common: support printing __m128i type"
and "[sanitizer] Fix VSNPrintf %V on Windows".

Unfortunately, custom "%V" is inherently incompatible with -Wformat,
it produces both:
warning: invalid conversion specifier 'V' [-Wformat-invalid-specifier]
warning: data argument not used by format string [-Wformat-extra-args]
If we disable both of these warnings we lose lots of useful warnings as well.

Depends on D107978.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107979
2021-08-13 13:44:21 +02:00
Dmitry Vyukov 036f963083 scudo: fix __attribute__((format))
The attribute should be in the header on declaration.
It's almost pointless in the source file.

Depends on D107977.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107978
2021-08-13 13:44:12 +02:00
Dmitry Vyukov 9c8f888f5f sanitizer_common: prepare for enabling format string checking
The __attribute__((format)) was added somewhere in 2012,
the lost during refactoring, then re-added in 2014 but
to te source files, which is a no-op.
Move it back to header files so that it actually takes effect.
But over the past 7 years we've accumulated whole lot of
format string bugs of different types, so disable the warning
with -Wno-format for now for incremental clean up.

Among the bugs that it warns about are all kinds of bad things:
 - wrong sizes of arguments
 - missing/excessive arguments
 - printing wrong things (e.g. *ptr instead of ptr)
 - completely messed up format strings
 - security issues where external string is used as format

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107977
2021-08-13 13:43:57 +02:00
Florian Mayer bae9527c20 [hwasan] Add report for wild frees.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D107577
2021-08-13 09:04:48 +01:00
Dmitry Vyukov 62139c5b25 tsan: remove implicit memcpy in MutexSet::Desc::operator=()
The default compiler-generated MutexSet::Desc::operator=()
now contains memcpy() call since Desc become bigger.
This fails in debug mode since we call interceptor from within the runtime.
Define own operator=() using internal_memcpy().
This also makes copy ctor necessary, otherwise:
tsan_mutexset.h:33:11: warning: definition of implicit copy constructor for
'Desc' is deprecated because it has a user-declared copy assignment operator
And if we add copy ctor, we also need the default ctor
since it's called by MutexSet ctor.

Depends on D107911.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107959
2021-08-12 15:10:05 +02:00
Dmitry Vyukov d9afba9000 tsan: extend MutexSet to memorize mutex address/stack_id
We currently memorize u64 id + epoch for each mutex.
The new tsan runtime will memorize address + stack_id instead.
But switching to address + stack_id requires new trace,
which in turn requires new MutexSet and some other changes.
Extend MutexSet to support both new and old info to break
the dependency cycles. The plan is to remove the old
info/methods after switching to the new runtime.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D107910
2021-08-12 13:18:43 +02:00
Dmitry Vyukov 645f5890ec tsan: fix build breakage due to AppMemBeg
AppMemBeg was renamed to LoAppMemBeg in 3830c93478
("tsan: rename kAppMemBeg to kLoAppMemBeg").
Rename remaining uses of the old name in tsan_platform_mac.cpp.

Differential Revision: https://reviews.llvm.org/D107948
2021-08-12 08:18:09 +02:00
Mitch Phillips 32adf108c8 [scudo] Add GWP-ASan state/metadata pointer proxies.
Provide accessor proxies for the gwp-asan regions that are useful in
symbolizing dumps offline. Should be useful for Fuchsia to be able to
locate these internal pointers to stash the data in a minidump.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D107909
2021-08-11 09:21:48 -07:00
Dmitry Vyukov 9af6156c52 tsan: fix active mapping selection
Fix bug introduced by commit 5d106f16b9.
SANITIZER_IOSSIM is always defined,
it's the value 0/1 that's meaningful.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D107888
2021-08-11 13:03:16 +02:00
Dmitry Vyukov 8af4725576 tsan: fix Printf format string
Reported on D107745

Reported-by: Wolfgang Pieb (wolfgangp)

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107881
2021-08-11 10:22:02 +02:00
Dmitry Vyukov 8233c343ad tsan: add notion of compressed addresses
New tsan runtime will need to compress addresses/PCs to fewer bits.
Add CompressAddr/RestoreAddr functions that compress/restore
addresses to 44 bits.

Depends on D107744.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107745
2021-08-10 20:09:16 +02:00
Dmitry Vyukov 1d9be7b4fa tsan: rename mapping field selectors
Rename mapping field selectors according to the code style.
Reuse the actual field names, there is no need to invent
second set of names.

Depends on D107743.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107744
2021-08-10 20:08:07 +02:00
Dmitry Vyukov 5d106f16b9 tsan: remove indirection when selecting the active mapping
Currently there are 2 levels when selecting the active mapping:
the branchy ifdef tree + another ifdef tree in SelectMapping.
Moreover, there is an additional indirection for some platforms
via HAS_48_BIT_ADDRESS_SPACE define. This makes already complex
logic even more complex and almost impossible to read.
Remove one level of indirection and define the active mapping
in SelectMapping.

Depends on D107742.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107743
2021-08-10 20:07:31 +02:00
Dmitry Vyukov 959076c596 tsan: remove dependencies on HAS_48_BIT_ADDRESS_SPACE and Mapping
Remove direct uses of Mapping in preperation for removing Mapping type
(which we already don't have for all platforms).
Remove dependence on HAS_48_BIT_ADDRESS_SPACE in preparation for removing it.
As far as I see for Apple/Mac platforms !HAS_48_BIT_ADDRESS_SPACE
simply means SANITIZER_IOS.

Depends on D107741.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107742
2021-08-10 20:07:23 +02:00
Dmitry Vyukov 0ebfe7c312 tsan: unit-test all mappings
Move the mapping checking logic from startup to unit tests
and test all mapping instead of just the active one.
This makes it much more feasible to make any global changes
to the mappings since we have 17 of them.

Depends on D107740.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D107741
2021-08-10 20:07:15 +02:00