2019-08-14 10:47:11 +02:00
|
|
|
//===-- asan_linux.cpp ----------------------------------------------------===//
|
2012-11-12 15:53:47 +00:00
|
|
|
//
|
2019-08-14 10:47:11 +02: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
|
2012-11-12 15:53:47 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Linux-specific details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-11-04 21:33:31 +00:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2018-10-31 12:14:23 +01:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_SOLARIS
|
2012-11-12 15:53:47 +00:00
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
# include <dlfcn.h>
|
|
|
|
# include <fcntl.h>
|
|
|
|
# include <limits.h>
|
|
|
|
# include <pthread.h>
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <sys/mman.h>
|
|
|
|
# include <sys/resource.h>
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <unwind.h>
|
|
|
|
|
|
|
|
# include "asan_interceptors.h"
|
|
|
|
# include "asan_internal.h"
|
|
|
|
# include "asan_premap_shadow.h"
|
|
|
|
# include "asan_thread.h"
|
|
|
|
# include "sanitizer_common/sanitizer_flags.h"
|
|
|
|
# include "sanitizer_common/sanitizer_freebsd.h"
|
|
|
|
# include "sanitizer_common/sanitizer_hash.h"
|
|
|
|
# include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
# include "sanitizer_common/sanitizer_procmaps.h"
|
|
|
|
|
|
|
|
# if SANITIZER_FREEBSD
|
|
|
|
# include <sys/link_elf.h>
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if SANITIZER_SOLARIS
|
|
|
|
# include <link.h>
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
|
|
|
|
# include <ucontext.h>
|
|
|
|
extern "C" void *_DYNAMIC;
|
|
|
|
# elif SANITIZER_NETBSD
|
|
|
|
# include <link_elf.h>
|
|
|
|
# include <ucontext.h>
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
extern Elf_Dyn _DYNAMIC;
|
2023-04-26 09:42:29 +02:00
|
|
|
# else
|
|
|
|
# include <link.h>
|
|
|
|
# include <sys/ucontext.h>
|
2021-05-12 14:37:22 +02:00
|
|
|
extern ElfW(Dyn) _DYNAMIC[];
|
2023-04-26 09:42:29 +02:00
|
|
|
# endif
|
2014-05-22 07:09:21 +00:00
|
|
|
|
2014-09-23 17:59:53 +00:00
|
|
|
// x86-64 FreeBSD 9.2 and older define 'ucontext_t' incorrectly in
|
|
|
|
// 32-bit mode.
|
2023-04-26 09:42:29 +02:00
|
|
|
# if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32) && \
|
|
|
|
__FreeBSD_version <= 902001 // v9.2
|
|
|
|
# define ucontext_t xucontext_t
|
|
|
|
# endif
|
2014-05-22 07:09:21 +00: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
|
2023-04-26 09:42:29 +02:00
|
|
|
asan_rt_version_t __asan_rt_version;
|
2014-05-22 07:09:21 +00:00
|
|
|
}
|
2012-11-12 15:53:47 +00:00
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
2015-10-21 10:32:45 +03:00
|
|
|
void InitializePlatformInterceptors() {}
|
2016-11-08 22:04:09 +00:00
|
|
|
void InitializePlatformExceptionHandlers() {}
|
2023-04-26 09:42:29 +02:00
|
|
|
bool IsSystemHeapAddress(uptr addr) { return false; }
|
2012-11-12 15:53:47 +00:00
|
|
|
|
|
|
|
void *AsanDoesNotSupportStaticLinkage() {
|
|
|
|
// This will fail to link with -static.
|
2021-05-12 14:37:22 +02:00
|
|
|
return &_DYNAMIC;
|
2012-11-12 15:53:47 +00:00
|
|
|
}
|
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
# if ASAN_PREMAP_SHADOW
|
2020-10-16 10:03:04 +02:00
|
|
|
uptr FindPremappedShadowStart(uptr shadow_size_bytes) {
|
2018-10-31 12:14:23 +01:00
|
|
|
uptr granularity = GetMmapGranularity();
|
|
|
|
uptr shadow_start = reinterpret_cast<uptr>(&__asan_shadow);
|
|
|
|
uptr premap_shadow_size = PremapShadowSize();
|
2020-10-16 10:03:04 +02:00
|
|
|
uptr shadow_size = RoundUpTo(shadow_size_bytes, granularity);
|
2018-10-31 12:14:23 +01:00
|
|
|
// We may have mapped too much. Release extra memory.
|
|
|
|
UnmapFromTo(shadow_start + shadow_size, shadow_start + premap_shadow_size);
|
|
|
|
return shadow_start;
|
|
|
|
}
|
2023-04-26 09:42:29 +02:00
|
|
|
# endif
|
2018-10-31 12:14:23 +01:00
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
uptr FindDynamicShadowStart() {
|
2020-10-16 10:03:04 +02:00
|
|
|
uptr shadow_size_bytes = MemToShadowSize(kHighMemEnd);
|
2023-04-26 09:42:29 +02:00
|
|
|
# if ASAN_PREMAP_SHADOW
|
2018-10-31 12:14:23 +01:00
|
|
|
if (!PremapShadowFailed())
|
2020-10-16 10:03:04 +02:00
|
|
|
return FindPremappedShadowStart(shadow_size_bytes);
|
2023-04-26 09:42:29 +02:00
|
|
|
# endif
|
2018-10-31 12:14:23 +01:00
|
|
|
|
2022-05-03 12:56:26 +02:00
|
|
|
return MapDynamicShadow(shadow_size_bytes, ASAN_SHADOW_SCALE,
|
2020-10-16 10:03:04 +02:00
|
|
|
/*min_shadow_base_alignment*/ 0, kHighMemEnd);
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 22:04:09 +00:00
|
|
|
void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2020-10-16 10:03:04 +02: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));
|
|
|
|
}
|
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
# if SANITIZER_ANDROID
|
2014-05-22 07:09:21 +00:00
|
|
|
// FIXME: should we do anything for Android?
|
|
|
|
void AsanCheckDynamicRTPrereqs() {}
|
|
|
|
void AsanCheckIncompatibleRT() {}
|
2023-04-26 09:42:29 +02:00
|
|
|
# else
|
2014-05-22 07:09:21 +00:00
|
|
|
static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size,
|
|
|
|
void *data) {
|
2021-11-04 09:20:14 +01:00
|
|
|
VReport(2, "info->dlpi_name = %s\tinfo->dlpi_addr = %p\n", info->dlpi_name,
|
|
|
|
(void *)info->dlpi_addr);
|
2018-10-31 12:14:23 +01:00
|
|
|
|
2022-05-03 12:56:26 +02:00
|
|
|
const char **name = (const char **)data;
|
2014-06-11 11:35:48 +00:00
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
// Ignore first entry (the main program)
|
2022-05-03 12:56:26 +02:00
|
|
|
if (!*name) {
|
|
|
|
*name = "";
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-03 12:56:26 +02:00
|
|
|
# if SANITIZER_LINUX
|
|
|
|
// Ignore vDSO. glibc versions earlier than 2.15 (and some patched
|
|
|
|
// by distributors) return an empty name for the vDSO entry, so
|
|
|
|
// detect this as well.
|
|
|
|
if (!info->dlpi_name[0] ||
|
|
|
|
internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0)
|
2018-10-31 12:14:23 +01:00
|
|
|
return 0;
|
2022-05-03 12:56:26 +02:00
|
|
|
# endif
|
2018-10-31 12:14:23 +01:00
|
|
|
|
2022-05-03 12:56:26 +02:00
|
|
|
*name = info->dlpi_name;
|
2014-05-22 07:09:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsDynamicRTName(const char *libname) {
|
|
|
|
return internal_strstr(libname, "libclang_rt.asan") ||
|
2023-04-26 09:42:29 +02:00
|
|
|
internal_strstr(libname, "libasan.so");
|
2014-05-22 07:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ReportIncompatibleRT() {
|
|
|
|
Report("Your application is linked against incompatible ASan runtimes.\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsanCheckDynamicRTPrereqs() {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (!ASAN_DYNAMIC || !flags()->verify_asan_link_order)
|
2015-10-21 10:32:45 +03:00
|
|
|
return;
|
|
|
|
|
2014-05-22 07:09:21 +00:00
|
|
|
// Ensure that dynamic RT is the first DSO in the list
|
2015-10-21 10:32:45 +03:00
|
|
|
const char *first_dso_name = nullptr;
|
2014-05-22 07:09:21 +00:00
|
|
|
dl_iterate_phdr(FindFirstDSOCallback, &first_dso_name);
|
2022-05-03 12:56:26 +02:00
|
|
|
if (first_dso_name && first_dso_name[0] && !IsDynamicRTName(first_dso_name)) {
|
2023-04-26 09:42:29 +02:00
|
|
|
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");
|
2014-05-22 07:09:21 +00:00
|
|
|
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) {
|
|
|
|
ReportIncompatibleRT();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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.
|
2023-04-26 09:42:29 +02:00
|
|
|
MemoryMappingLayout proc_maps(/*cache_enabled*/ true);
|
2018-10-31 12:14:23 +01:00
|
|
|
char filename[PATH_MAX];
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
MemoryMappedSegment segment(filename, sizeof(filename));
|
|
|
|
while (proc_maps.Next(&segment)) {
|
|
|
|
if (IsDynamicRTName(segment.filename)) {
|
2023-04-26 09:42:29 +02:00
|
|
|
Report(
|
|
|
|
"Your application is linked against "
|
|
|
|
"incompatible ASan runtimes.\n");
|
2014-05-22 07:09:21 +00:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__asan_rt_version = ASAN_RT_VERSION_STATIC;
|
|
|
|
} else if (__asan_rt_version != ASAN_RT_VERSION_STATIC) {
|
|
|
|
ReportIncompatibleRT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-26 09:42:29 +02:00
|
|
|
# endif // SANITIZER_ANDROID
|
2012-11-12 15:53:47 +00:00
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
# if ASAN_INTERCEPT_SWAPCONTEXT
|
|
|
|
constexpr u32 kAsanContextStackFlagsMagic = 0x51260eea;
|
|
|
|
|
|
|
|
static int HashContextStack(const ucontext_t &ucp) {
|
|
|
|
MurMur2Hash64Builder hash(kAsanContextStackFlagsMagic);
|
|
|
|
hash.add(reinterpret_cast<uptr>(ucp.uc_stack.ss_sp));
|
|
|
|
hash.add(ucp.uc_stack.ss_size);
|
|
|
|
return static_cast<int>(hash.get());
|
2012-11-23 14:46:25 +00:00
|
|
|
}
|
2022-08-30 11:45:34 +02:00
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
void SignContextStack(void *context) {
|
|
|
|
ucontext_t *ucp = reinterpret_cast<ucontext_t *>(context);
|
|
|
|
ucp->uc_stack.ss_flags = HashContextStack(*ucp);
|
2022-08-30 11:45:34 +02:00
|
|
|
}
|
2023-04-26 09:42:29 +02:00
|
|
|
|
2013-01-23 11:41:33 +00:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
|
2023-04-26 09:42:29 +02:00
|
|
|
const ucontext_t *ucp = reinterpret_cast<const ucontext_t *>(context);
|
|
|
|
if (HashContextStack(*ucp) == ucp->uc_stack.ss_flags) {
|
|
|
|
*stack = reinterpret_cast<uptr>(ucp->uc_stack.ss_sp);
|
|
|
|
*ssize = ucp->uc_stack.ss_size;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*stack = 0;
|
|
|
|
*ssize = 0;
|
2012-11-23 14:46:25 +00:00
|
|
|
}
|
2023-04-26 09:42:29 +02:00
|
|
|
# endif // ASAN_INTERCEPT_SWAPCONTEXT
|
2022-08-30 11:45:34 +02:00
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
void *AsanDlSymNext(const char *sym) { return dlsym(RTLD_NEXT, sym); }
|
2014-09-23 17:59:53 +00:00
|
|
|
|
2019-08-14 10:47:11 +02: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;
|
|
|
|
}
|
|
|
|
|
2023-04-26 09:42:29 +02:00
|
|
|
} // namespace __asan
|
2012-11-12 15:53:47 +00:00
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
|
|
|
|
// SANITIZER_SOLARIS
|