2019-08-01 21:43:28 +08:00
|
|
|
//===-- asan_linux.cpp ----------------------------------------------------===//
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Linux-specific details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-19 22:33:38 +08:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_SOLARIS
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-01-05 08:44:33 +08:00
|
|
|
#include "asan_interceptors.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
#include "asan_internal.h"
|
2017-11-21 01:41:57 +08:00
|
|
|
#include "asan_premap_shadow.h"
|
2012-01-05 09:07:27 +08:00
|
|
|
#include "asan_thread.h"
|
2014-03-04 21:12:25 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2014-06-15 21:56:28 +08:00
|
|
|
#include "sanitizer_common/sanitizer_freebsd.h"
|
2012-06-04 22:27:50 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2012-06-07 14:15:12 +08:00
|
|
|
#include "sanitizer_common/sanitizer_procmaps.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-01-05 09:07:27 +08:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
2011-11-30 09:07:02 +08:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/syscall.h>
|
2011-12-29 06:58:01 +08:00
|
|
|
#include <sys/types.h>
|
2014-06-06 18:57:21 +08:00
|
|
|
#include <dlfcn.h>
|
2011-12-29 06:58:01 +08:00
|
|
|
#include <fcntl.h>
|
2018-02-08 02:27:25 +08:00
|
|
|
#include <limits.h>
|
2012-01-05 09:07:27 +08:00
|
|
|
#include <pthread.h>
|
2012-01-05 08:44:33 +08:00
|
|
|
#include <stdio.h>
|
2011-11-30 09:07:02 +08:00
|
|
|
#include <unistd.h>
|
2012-01-19 19:34:18 +08:00
|
|
|
#include <unwind.h>
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2014-04-09 21:37:19 +08:00
|
|
|
#if SANITIZER_FREEBSD
|
|
|
|
#include <sys/link_elf.h>
|
|
|
|
#endif
|
|
|
|
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#if SANITIZER_SOLARIS
|
|
|
|
#include <link.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
|
2014-02-10 21:34:43 +08:00
|
|
|
#include <ucontext.h>
|
2014-04-01 21:16:30 +08:00
|
|
|
extern "C" void* _DYNAMIC;
|
2017-08-11 02:51:51 +08:00
|
|
|
#elif SANITIZER_NETBSD
|
|
|
|
#include <link_elf.h>
|
|
|
|
#include <ucontext.h>
|
|
|
|
extern Elf_Dyn _DYNAMIC;
|
2014-02-10 21:34:43 +08:00
|
|
|
#else
|
2012-01-07 03:11:09 +08:00
|
|
|
#include <sys/ucontext.h>
|
2014-04-01 21:16:30 +08:00
|
|
|
#include <link.h>
|
2020-12-28 12:28:59 +08:00
|
|
|
extern ElfW(Dyn) _DYNAMIC[];
|
2012-01-07 03:11:09 +08:00
|
|
|
#endif
|
|
|
|
|
2014-06-15 21:56:28 +08:00
|
|
|
// x86-64 FreeBSD 9.2 and older define 'ucontext_t' incorrectly in
|
|
|
|
// 32-bit mode.
|
|
|
|
#if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32) && \
|
|
|
|
__FreeBSD_version <= 902001 // v9.2
|
|
|
|
#define ucontext_t xucontext_t
|
2014-03-12 20:44:36 +08:00
|
|
|
#endif
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
typedef enum {
|
|
|
|
ASAN_RT_VERSION_UNDEFINED = 0,
|
|
|
|
ASAN_RT_VERSION_DYNAMIC,
|
|
|
|
ASAN_RT_VERSION_STATIC,
|
|
|
|
} asan_rt_version_t;
|
|
|
|
|
|
|
|
// FIXME: perhaps also store abi version here?
|
|
|
|
extern "C" {
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
asan_rt_version_t __asan_rt_version;
|
|
|
|
}
|
2012-03-26 17:48:41 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
namespace __asan {
|
|
|
|
|
2015-03-16 22:22:53 +08:00
|
|
|
void InitializePlatformInterceptors() {}
|
2016-07-12 05:40:59 +08:00
|
|
|
void InitializePlatformExceptionHandlers() {}
|
2017-02-22 00:09:38 +08:00
|
|
|
bool IsSystemHeapAddress (uptr addr) { return false; }
|
2015-03-16 22:22:53 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
void *AsanDoesNotSupportStaticLinkage() {
|
|
|
|
// This will fail to link with -static.
|
2020-12-28 12:28:59 +08:00
|
|
|
return &_DYNAMIC;
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 01:41:57 +08:00
|
|
|
#if ASAN_PREMAP_SHADOW
|
[compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI)
Summary:
This refactors some common support related to shadow memory setup from
asan and hwasan into sanitizer_common. This should not only reduce code
duplication but also make these facilities available for new compiler-rt
uses (e.g. heap profiling).
In most cases the separate copies of the code were either identical, or
at least functionally identical. A few notes:
In ProtectGap, the asan version checked the address against an upper
bound (kZeroBaseMaxShadowStart, which is (2^18). I have created a copy
of kZeroBaseMaxShadowStart in hwasan_mapping.h, with the same value, as
it isn't clear why that code should not do the same check. If it
shouldn't, I can remove this and guard this check so that it only
happens for asan.
In asan's InitializeShadowMemory, in the dynamic shadow case it was
setting __asan_shadow_memory_dynamic_address to 0 (which then sets both
macro SHADOW_OFFSET as well as macro kLowShadowBeg to 0) before calling
FindDynamicShadowStart(). AFAICT this is only needed because
FindDynamicShadowStart utilizes kHighShadowEnd to
get the shadow size, and kHighShadowEnd is a macro invoking
MEM_TO_SHADOW(kHighMemEnd) which in turn invokes:
(((kHighMemEnd) >> SHADOW_SCALE) + (SHADOW_OFFSET))
I.e. it computes the shadow space needed by kHighMemEnd (the shift), and
adds the offset. Since we only want the shadow space here, the earlier
setting of SHADOW_OFFSET to 0 via __asan_shadow_memory_dynamic_address
accomplishes this. In the hwasan version, it simply gets the shadow
space via "MemToShadowSize(kHighMemEnd)", where MemToShadowSize just
does the shift. I've simplified the asan handling to do the same
thing, and therefore was able to remove the setting of the SHADOW_OFFSET
via __asan_shadow_memory_dynamic_address to 0.
Reviewers: vitalybuka, kcc, eugenis
Subscribers: dberris, #sanitizers, llvm-commits, davidxl
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83247
2020-07-07 02:05:12 +08:00
|
|
|
uptr FindPremappedShadowStart(uptr shadow_size_bytes) {
|
2017-11-21 01:41:57 +08:00
|
|
|
uptr granularity = GetMmapGranularity();
|
|
|
|
uptr shadow_start = reinterpret_cast<uptr>(&__asan_shadow);
|
|
|
|
uptr premap_shadow_size = PremapShadowSize();
|
[compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI)
Summary:
This refactors some common support related to shadow memory setup from
asan and hwasan into sanitizer_common. This should not only reduce code
duplication but also make these facilities available for new compiler-rt
uses (e.g. heap profiling).
In most cases the separate copies of the code were either identical, or
at least functionally identical. A few notes:
In ProtectGap, the asan version checked the address against an upper
bound (kZeroBaseMaxShadowStart, which is (2^18). I have created a copy
of kZeroBaseMaxShadowStart in hwasan_mapping.h, with the same value, as
it isn't clear why that code should not do the same check. If it
shouldn't, I can remove this and guard this check so that it only
happens for asan.
In asan's InitializeShadowMemory, in the dynamic shadow case it was
setting __asan_shadow_memory_dynamic_address to 0 (which then sets both
macro SHADOW_OFFSET as well as macro kLowShadowBeg to 0) before calling
FindDynamicShadowStart(). AFAICT this is only needed because
FindDynamicShadowStart utilizes kHighShadowEnd to
get the shadow size, and kHighShadowEnd is a macro invoking
MEM_TO_SHADOW(kHighMemEnd) which in turn invokes:
(((kHighMemEnd) >> SHADOW_SCALE) + (SHADOW_OFFSET))
I.e. it computes the shadow space needed by kHighMemEnd (the shift), and
adds the offset. Since we only want the shadow space here, the earlier
setting of SHADOW_OFFSET to 0 via __asan_shadow_memory_dynamic_address
accomplishes this. In the hwasan version, it simply gets the shadow
space via "MemToShadowSize(kHighMemEnd)", where MemToShadowSize just
does the shift. I've simplified the asan handling to do the same
thing, and therefore was able to remove the setting of the SHADOW_OFFSET
via __asan_shadow_memory_dynamic_address to 0.
Reviewers: vitalybuka, kcc, eugenis
Subscribers: dberris, #sanitizers, llvm-commits, davidxl
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83247
2020-07-07 02:05:12 +08:00
|
|
|
uptr shadow_size = RoundUpTo(shadow_size_bytes, granularity);
|
2017-11-21 01:41:57 +08:00
|
|
|
// We may have mapped too much. Release extra memory.
|
|
|
|
UnmapFromTo(shadow_start + shadow_size, shadow_start + premap_shadow_size);
|
|
|
|
return shadow_start;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-11 06:27:48 +08:00
|
|
|
uptr FindDynamicShadowStart() {
|
[compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI)
Summary:
This refactors some common support related to shadow memory setup from
asan and hwasan into sanitizer_common. This should not only reduce code
duplication but also make these facilities available for new compiler-rt
uses (e.g. heap profiling).
In most cases the separate copies of the code were either identical, or
at least functionally identical. A few notes:
In ProtectGap, the asan version checked the address against an upper
bound (kZeroBaseMaxShadowStart, which is (2^18). I have created a copy
of kZeroBaseMaxShadowStart in hwasan_mapping.h, with the same value, as
it isn't clear why that code should not do the same check. If it
shouldn't, I can remove this and guard this check so that it only
happens for asan.
In asan's InitializeShadowMemory, in the dynamic shadow case it was
setting __asan_shadow_memory_dynamic_address to 0 (which then sets both
macro SHADOW_OFFSET as well as macro kLowShadowBeg to 0) before calling
FindDynamicShadowStart(). AFAICT this is only needed because
FindDynamicShadowStart utilizes kHighShadowEnd to
get the shadow size, and kHighShadowEnd is a macro invoking
MEM_TO_SHADOW(kHighMemEnd) which in turn invokes:
(((kHighMemEnd) >> SHADOW_SCALE) + (SHADOW_OFFSET))
I.e. it computes the shadow space needed by kHighMemEnd (the shift), and
adds the offset. Since we only want the shadow space here, the earlier
setting of SHADOW_OFFSET to 0 via __asan_shadow_memory_dynamic_address
accomplishes this. In the hwasan version, it simply gets the shadow
space via "MemToShadowSize(kHighMemEnd)", where MemToShadowSize just
does the shift. I've simplified the asan handling to do the same
thing, and therefore was able to remove the setting of the SHADOW_OFFSET
via __asan_shadow_memory_dynamic_address to 0.
Reviewers: vitalybuka, kcc, eugenis
Subscribers: dberris, #sanitizers, llvm-commits, davidxl
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83247
2020-07-07 02:05:12 +08:00
|
|
|
uptr shadow_size_bytes = MemToShadowSize(kHighMemEnd);
|
2017-11-21 01:41:57 +08:00
|
|
|
#if ASAN_PREMAP_SHADOW
|
|
|
|
if (!PremapShadowFailed())
|
[compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI)
Summary:
This refactors some common support related to shadow memory setup from
asan and hwasan into sanitizer_common. This should not only reduce code
duplication but also make these facilities available for new compiler-rt
uses (e.g. heap profiling).
In most cases the separate copies of the code were either identical, or
at least functionally identical. A few notes:
In ProtectGap, the asan version checked the address against an upper
bound (kZeroBaseMaxShadowStart, which is (2^18). I have created a copy
of kZeroBaseMaxShadowStart in hwasan_mapping.h, with the same value, as
it isn't clear why that code should not do the same check. If it
shouldn't, I can remove this and guard this check so that it only
happens for asan.
In asan's InitializeShadowMemory, in the dynamic shadow case it was
setting __asan_shadow_memory_dynamic_address to 0 (which then sets both
macro SHADOW_OFFSET as well as macro kLowShadowBeg to 0) before calling
FindDynamicShadowStart(). AFAICT this is only needed because
FindDynamicShadowStart utilizes kHighShadowEnd to
get the shadow size, and kHighShadowEnd is a macro invoking
MEM_TO_SHADOW(kHighMemEnd) which in turn invokes:
(((kHighMemEnd) >> SHADOW_SCALE) + (SHADOW_OFFSET))
I.e. it computes the shadow space needed by kHighMemEnd (the shift), and
adds the offset. Since we only want the shadow space here, the earlier
setting of SHADOW_OFFSET to 0 via __asan_shadow_memory_dynamic_address
accomplishes this. In the hwasan version, it simply gets the shadow
space via "MemToShadowSize(kHighMemEnd)", where MemToShadowSize just
does the shift. I've simplified the asan handling to do the same
thing, and therefore was able to remove the setting of the SHADOW_OFFSET
via __asan_shadow_memory_dynamic_address to 0.
Reviewers: vitalybuka, kcc, eugenis
Subscribers: dberris, #sanitizers, llvm-commits, davidxl
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83247
2020-07-07 02:05:12 +08:00
|
|
|
return FindPremappedShadowStart(shadow_size_bytes);
|
2017-11-21 01:41:57 +08:00
|
|
|
#endif
|
|
|
|
|
[compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI)
Summary:
This refactors some common support related to shadow memory setup from
asan and hwasan into sanitizer_common. This should not only reduce code
duplication but also make these facilities available for new compiler-rt
uses (e.g. heap profiling).
In most cases the separate copies of the code were either identical, or
at least functionally identical. A few notes:
In ProtectGap, the asan version checked the address against an upper
bound (kZeroBaseMaxShadowStart, which is (2^18). I have created a copy
of kZeroBaseMaxShadowStart in hwasan_mapping.h, with the same value, as
it isn't clear why that code should not do the same check. If it
shouldn't, I can remove this and guard this check so that it only
happens for asan.
In asan's InitializeShadowMemory, in the dynamic shadow case it was
setting __asan_shadow_memory_dynamic_address to 0 (which then sets both
macro SHADOW_OFFSET as well as macro kLowShadowBeg to 0) before calling
FindDynamicShadowStart(). AFAICT this is only needed because
FindDynamicShadowStart utilizes kHighShadowEnd to
get the shadow size, and kHighShadowEnd is a macro invoking
MEM_TO_SHADOW(kHighMemEnd) which in turn invokes:
(((kHighMemEnd) >> SHADOW_SCALE) + (SHADOW_OFFSET))
I.e. it computes the shadow space needed by kHighMemEnd (the shift), and
adds the offset. Since we only want the shadow space here, the earlier
setting of SHADOW_OFFSET to 0 via __asan_shadow_memory_dynamic_address
accomplishes this. In the hwasan version, it simply gets the shadow
space via "MemToShadowSize(kHighMemEnd)", where MemToShadowSize just
does the shift. I've simplified the asan handling to do the same
thing, and therefore was able to remove the setting of the SHADOW_OFFSET
via __asan_shadow_memory_dynamic_address to 0.
Reviewers: vitalybuka, kcc, eugenis
Subscribers: dberris, #sanitizers, llvm-commits, davidxl
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83247
2020-07-07 02:05:12 +08:00
|
|
|
return MapDynamicShadow(shadow_size_bytes, SHADOW_SCALE,
|
|
|
|
/*min_shadow_base_alignment*/ 0, kHighMemEnd);
|
2017-11-11 06:27:48 +08:00
|
|
|
}
|
2017-07-13 07:29:21 +08:00
|
|
|
|
2016-03-29 04:28:17 +08:00
|
|
|
void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2020-07-22 02:06:15 +08:00
|
|
|
void FlushUnneededASanShadowMemory(uptr p, uptr size) {
|
|
|
|
// Since asan's mapping is compacting, the shadow chunk may be
|
|
|
|
// not page-aligned, so we only flush the page-aligned portion.
|
|
|
|
ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
|
|
|
|
}
|
|
|
|
|
2014-04-02 17:36:36 +08:00
|
|
|
#if SANITIZER_ANDROID
|
|
|
|
// FIXME: should we do anything for Android?
|
|
|
|
void AsanCheckDynamicRTPrereqs() {}
|
|
|
|
void AsanCheckIncompatibleRT() {}
|
|
|
|
#else
|
2014-04-01 21:16:30 +08:00
|
|
|
static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size,
|
|
|
|
void *data) {
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
VReport(2, "info->dlpi_name = %s\tinfo->dlpi_addr = %p\n",
|
|
|
|
info->dlpi_name, info->dlpi_addr);
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
// Continue until the first dynamic library is found
|
|
|
|
if (!info->dlpi_name || info->dlpi_name[0] == 0)
|
|
|
|
return 0;
|
|
|
|
|
2014-06-02 18:39:40 +08:00
|
|
|
// Ignore vDSO
|
|
|
|
if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2017-10-25 03:45:59 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
|
2017-08-11 02:51:51 +08:00
|
|
|
// Ignore first entry (the main program)
|
|
|
|
char **p = (char **)data;
|
|
|
|
if (!(*p)) {
|
|
|
|
*p = (char *)-1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#if SANITIZER_SOLARIS
|
|
|
|
// Ignore executable on Solaris
|
|
|
|
if (info->dlpi_addr == 0)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
*(const char **)data = info->dlpi_name;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsDynamicRTName(const char *libname) {
|
|
|
|
return internal_strstr(libname, "libclang_rt.asan") ||
|
|
|
|
internal_strstr(libname, "libasan.so");
|
|
|
|
}
|
|
|
|
|
2014-04-02 21:09:22 +08:00
|
|
|
static void ReportIncompatibleRT() {
|
|
|
|
Report("Your application is linked against incompatible ASan runtimes.\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
void AsanCheckDynamicRTPrereqs() {
|
2017-03-31 14:36:37 +08:00
|
|
|
if (!ASAN_DYNAMIC || !flags()->verify_asan_link_order)
|
2015-06-04 15:23:09 +08:00
|
|
|
return;
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
// Ensure that dynamic RT is the first DSO in the list
|
2015-10-01 08:22:21 +08:00
|
|
|
const char *first_dso_name = nullptr;
|
2014-04-01 21:16:30 +08:00
|
|
|
dl_iterate_phdr(FindFirstDSOCallback, &first_dso_name);
|
|
|
|
if (first_dso_name && !IsDynamicRTName(first_dso_name)) {
|
|
|
|
Report("ASan runtime does not come first in initial library list; "
|
|
|
|
"you should either link runtime to your application or "
|
|
|
|
"manually preload it with LD_PRELOAD.\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsanCheckIncompatibleRT() {
|
|
|
|
if (ASAN_DYNAMIC) {
|
|
|
|
if (__asan_rt_version == ASAN_RT_VERSION_UNDEFINED) {
|
|
|
|
__asan_rt_version = ASAN_RT_VERSION_DYNAMIC;
|
|
|
|
} else if (__asan_rt_version != ASAN_RT_VERSION_DYNAMIC) {
|
2014-04-02 21:09:22 +08:00
|
|
|
ReportIncompatibleRT();
|
2014-04-01 21:16:30 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-02 21:09:22 +08:00
|
|
|
if (__asan_rt_version == ASAN_RT_VERSION_UNDEFINED) {
|
|
|
|
// Ensure that dynamic runtime is not present. We should detect it
|
|
|
|
// as early as possible, otherwise ASan interceptors could bind to
|
|
|
|
// the functions in dynamic ASan runtime instead of the functions in
|
|
|
|
// system libraries, causing crashes later in ASan initialization.
|
|
|
|
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
|
2018-02-08 02:27:25 +08:00
|
|
|
char filename[PATH_MAX];
|
2017-07-12 02:54:00 +08:00
|
|
|
MemoryMappedSegment segment(filename, sizeof(filename));
|
|
|
|
while (proc_maps.Next(&segment)) {
|
|
|
|
if (IsDynamicRTName(segment.filename)) {
|
2014-04-02 21:09:22 +08:00
|
|
|
Report("Your application is linked against "
|
|
|
|
"incompatible ASan runtimes.\n");
|
|
|
|
Die();
|
|
|
|
}
|
2014-04-01 21:16:30 +08:00
|
|
|
}
|
2014-04-02 21:09:22 +08:00
|
|
|
__asan_rt_version = ASAN_RT_VERSION_STATIC;
|
|
|
|
} else if (__asan_rt_version != ASAN_RT_VERSION_STATIC) {
|
|
|
|
ReportIncompatibleRT();
|
2014-04-01 21:16:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 08:22:21 +08:00
|
|
|
#endif // SANITIZER_ANDROID
|
2014-04-01 21:16:30 +08:00
|
|
|
|
2013-03-19 21:54:41 +08:00
|
|
|
#if !SANITIZER_ANDROID
|
2013-01-17 23:45:28 +08:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
|
2012-11-23 18:14:44 +08:00
|
|
|
ucontext_t *ucp = (ucontext_t*)context;
|
2013-01-17 23:45:28 +08:00
|
|
|
*stack = (uptr)ucp->uc_stack.ss_sp;
|
|
|
|
*ssize = ucp->uc_stack.ss_size;
|
2012-11-23 18:14:44 +08:00
|
|
|
}
|
|
|
|
#else
|
2013-01-17 23:45:28 +08:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
|
2013-01-18 17:20:06 +08:00
|
|
|
UNIMPLEMENTED();
|
2012-11-23 18:14:44 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-06 18:57:21 +08:00
|
|
|
void *AsanDlSymNext(const char *sym) {
|
|
|
|
return dlsym(RTLD_NEXT, sym);
|
|
|
|
}
|
|
|
|
|
2018-12-01 23:45:42 +08:00
|
|
|
bool HandleDlopenInit() {
|
|
|
|
// Not supported on this platform.
|
|
|
|
static_assert(!SANITIZER_SUPPORTS_INIT_FOR_DLOPEN,
|
|
|
|
"Expected SANITIZER_SUPPORTS_INIT_FOR_DLOPEN to be false");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:22:21 +08:00
|
|
|
} // namespace __asan
|
2011-12-02 05:40:52 +08:00
|
|
|
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
|
|
|
|
// SANITIZER_SOLARIS
|