2012-10-12 01:08:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
2017-02-16 00:31:13 +01:00
|
|
|
* All rights reserved.
|
2012-10-12 01:08:51 +02:00
|
|
|
*
|
2017-02-16 00:31:13 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2012-10-12 01:08:51 +02:00
|
|
|
*
|
2017-02-16 00:31:13 +01:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2012-10-12 01:08:51 +02:00
|
|
|
*/
|
|
|
|
|
2012-10-17 00:54:46 +02:00
|
|
|
#include "linker.h"
|
2016-07-06 22:20:59 +02:00
|
|
|
#include "linker_cfi.h"
|
Add the recoverable GWP-ASan feature.
GWP-ASan's recoverable mode was landed upstream in
https://reviews.llvm.org/D140173.
This mode allows for a use-after-free or a buffer-overflow bug to be
detected by GWP-ASan, a crash report dumped, but then GWP-ASan (through
the preCrashReport() and postCrashReportRecoverableOnly() hooks) will
patch up the memory so that the process can continue, in spite of the
memory safety bug.
This is desirable, as it allows us to consider migrating non-system apps
from opt-in GWP-ASan to opt-out GWP-ASan. The major concern was "if we
make it opt-out, then bad apps will start crashing". If we don't crash,
problem solved :). Obviously, we'll need to do this with an amount of
process sampling to mitigate against the 70KiB memory overhead.
The biggest problem is that the debuggerd signal handler isn't the first
signal handler for apps, it's the sigchain handler inside of libart.
Clearly, the sigchain handler needs to ask us whether the crash is
GWP-ASan's fault, and if so, please patch up the allocator. Because of
linker namespace restrictions, libart can't directly ask the linker
(which is where debuggerd lies), so we provide a proxy function in libc.
Test: Build the platform, run sanitizer-status and various test apps
with recoverable gwp-asan. Assert that it doesn't crash, and we get a
debuggerd report.
Bug: 247012630
Change-Id: I86d5e27a9ca5531c8942e62647fd377c3cd36dfd
2023-01-19 21:47:22 +01:00
|
|
|
#include "linker_debuggerd.h"
|
2016-07-21 20:33:40 +02:00
|
|
|
#include "linker_dlwarning.h"
|
Add the recoverable GWP-ASan feature.
GWP-ASan's recoverable mode was landed upstream in
https://reviews.llvm.org/D140173.
This mode allows for a use-after-free or a buffer-overflow bug to be
detected by GWP-ASan, a crash report dumped, but then GWP-ASan (through
the preCrashReport() and postCrashReportRecoverableOnly() hooks) will
patch up the memory so that the process can continue, in spite of the
memory safety bug.
This is desirable, as it allows us to consider migrating non-system apps
from opt-in GWP-ASan to opt-out GWP-ASan. The major concern was "if we
make it opt-out, then bad apps will start crashing". If we don't crash,
problem solved :). Obviously, we'll need to do this with an amount of
process sampling to mitigate against the 70KiB memory overhead.
The biggest problem is that the debuggerd signal handler isn't the first
signal handler for apps, it's the sigchain handler inside of libart.
Clearly, the sigchain handler needs to ask us whether the crash is
GWP-ASan's fault, and if so, please patch up the allocator. Because of
linker namespace restrictions, libart can't directly ask the linker
(which is where debuggerd lies), so we provide a proxy function in libc.
Test: Build the platform, run sanitizer-status and various test apps
with recoverable gwp-asan. Assert that it doesn't crash, and we get a
debuggerd report.
Bug: 247012630
Change-Id: I86d5e27a9ca5531c8942e62647fd377c3cd36dfd
2023-01-19 21:47:22 +01:00
|
|
|
#include "linker_globals.h"
|
2012-10-17 00:54:46 +02:00
|
|
|
|
2019-10-15 01:58:53 +02:00
|
|
|
#include <link.h>
|
2012-10-12 01:08:51 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
2012-10-17 00:54:46 +02:00
|
|
|
#include <stdlib.h>
|
2015-01-29 03:02:33 +01:00
|
|
|
#include <string.h>
|
2015-06-03 02:36:54 +02:00
|
|
|
#include <android/api-level.h>
|
2012-10-12 01:08:51 +02:00
|
|
|
|
2012-10-17 00:54:46 +02:00
|
|
|
#include <bionic/pthread_internal.h>
|
2018-11-22 11:40:17 +01:00
|
|
|
#include "private/bionic_globals.h"
|
2013-10-10 00:50:50 +02:00
|
|
|
#include "private/bionic_tls.h"
|
|
|
|
#include "private/ScopedPthreadMutexLocker.h"
|
2012-10-12 01:08:51 +02:00
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
#define __LINKER_PUBLIC__ __attribute__((visibility("default")))
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
android_namespace_t* __loader_android_create_namespace(const char* name,
|
|
|
|
const char* ld_library_path,
|
|
|
|
const char* default_library_path,
|
|
|
|
uint64_t type,
|
|
|
|
const char* permitted_when_isolated_path,
|
|
|
|
android_namespace_t* parent_namespace,
|
|
|
|
const void* caller_addr) __LINKER_PUBLIC__;
|
|
|
|
void* __loader_android_dlopen_ext(const char* filename,
|
|
|
|
int flags,
|
|
|
|
const android_dlextinfo* extinfo,
|
|
|
|
const void* caller_addr) __LINKER_PUBLIC__;
|
|
|
|
void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*)) __LINKER_PUBLIC__;
|
2018-11-13 01:01:37 +01:00
|
|
|
int __loader_android_get_application_target_sdk_version() __LINKER_PUBLIC__;
|
2017-08-29 18:14:49 +02:00
|
|
|
void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) __LINKER_PUBLIC__;
|
|
|
|
android_namespace_t* __loader_android_get_exported_namespace(const char* name) __LINKER_PUBLIC__;
|
|
|
|
bool __loader_android_init_anonymous_namespace(const char* shared_libs_sonames,
|
|
|
|
const char* library_search_path) __LINKER_PUBLIC__;
|
|
|
|
bool __loader_android_link_namespaces(android_namespace_t* namespace_from,
|
|
|
|
android_namespace_t* namespace_to,
|
|
|
|
const char* shared_libs_sonames) __LINKER_PUBLIC__;
|
2018-01-18 05:05:09 +01:00
|
|
|
bool __loader_android_link_namespaces_all_libs(android_namespace_t* namespace_from,
|
|
|
|
android_namespace_t* namespace_to) __LINKER_PUBLIC__;
|
2018-11-13 01:01:37 +01:00
|
|
|
void __loader_android_set_application_target_sdk_version(int target) __LINKER_PUBLIC__;
|
2017-08-29 18:14:49 +02:00
|
|
|
void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path) __LINKER_PUBLIC__;
|
|
|
|
void __loader_cfi_fail(uint64_t CallSiteTypeId,
|
|
|
|
void* Ptr,
|
|
|
|
void *DiagData,
|
|
|
|
void *CallerPc) __LINKER_PUBLIC__;
|
|
|
|
int __loader_dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data),
|
|
|
|
void* data) __LINKER_PUBLIC__;
|
|
|
|
int __loader_dladdr(const void* addr, Dl_info* info) __LINKER_PUBLIC__;
|
|
|
|
int __loader_dlclose(void* handle) __LINKER_PUBLIC__;
|
|
|
|
char* __loader_dlerror() __LINKER_PUBLIC__;
|
|
|
|
void* __loader_dlopen(const char* filename, int flags, const void* caller_addr) __LINKER_PUBLIC__;
|
|
|
|
void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr) __LINKER_PUBLIC__;
|
|
|
|
void* __loader_dlvsym(void* handle,
|
|
|
|
const char* symbol,
|
|
|
|
const char* version,
|
|
|
|
const void* caller_addr) __LINKER_PUBLIC__;
|
2018-01-05 11:39:28 +01:00
|
|
|
void __loader_add_thread_local_dtor(void* dso_handle) __LINKER_PUBLIC__;
|
|
|
|
void __loader_remove_thread_local_dtor(void* dso_handle) __LINKER_PUBLIC__;
|
2018-11-22 11:40:17 +01:00
|
|
|
libc_shared_globals* __loader_shared_globals() __LINKER_PUBLIC__;
|
2017-08-29 18:14:49 +02:00
|
|
|
#if defined(__arm__)
|
|
|
|
_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) __LINKER_PUBLIC__;
|
|
|
|
#endif
|
Add the recoverable GWP-ASan feature.
GWP-ASan's recoverable mode was landed upstream in
https://reviews.llvm.org/D140173.
This mode allows for a use-after-free or a buffer-overflow bug to be
detected by GWP-ASan, a crash report dumped, but then GWP-ASan (through
the preCrashReport() and postCrashReportRecoverableOnly() hooks) will
patch up the memory so that the process can continue, in spite of the
memory safety bug.
This is desirable, as it allows us to consider migrating non-system apps
from opt-in GWP-ASan to opt-out GWP-ASan. The major concern was "if we
make it opt-out, then bad apps will start crashing". If we don't crash,
problem solved :). Obviously, we'll need to do this with an amount of
process sampling to mitigate against the 70KiB memory overhead.
The biggest problem is that the debuggerd signal handler isn't the first
signal handler for apps, it's the sigchain handler inside of libart.
Clearly, the sigchain handler needs to ask us whether the crash is
GWP-ASan's fault, and if so, please patch up the allocator. Because of
linker namespace restrictions, libart can't directly ask the linker
(which is where debuggerd lies), so we provide a proxy function in libc.
Test: Build the platform, run sanitizer-status and various test apps
with recoverable gwp-asan. Assert that it doesn't crash, and we get a
debuggerd report.
Bug: 247012630
Change-Id: I86d5e27a9ca5531c8942e62647fd377c3cd36dfd
2023-01-19 21:47:22 +01:00
|
|
|
bool __loader_android_handle_signal(int signal_number, siginfo_t* info,
|
|
|
|
void* context) __LINKER_PUBLIC__;
|
2017-08-29 18:14:49 +02:00
|
|
|
}
|
|
|
|
|
2023-07-22 08:04:50 +02:00
|
|
|
pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
2012-10-12 01:08:51 +02:00
|
|
|
|
2016-08-12 00:02:45 +02:00
|
|
|
static char* __bionic_set_dlerror(char* new_value) {
|
2018-11-14 00:30:07 +01:00
|
|
|
char* old_value = __get_thread()->current_dlerror;
|
|
|
|
__get_thread()->current_dlerror = new_value;
|
2012-10-12 01:08:51 +02:00
|
|
|
|
2017-04-15 18:11:15 +02:00
|
|
|
if (new_value != nullptr) LD_LOG(kLogErrors, "dlerror set to \"%s\"", new_value);
|
2012-10-17 00:54:46 +02:00
|
|
|
return old_value;
|
|
|
|
}
|
2012-10-12 01:08:51 +02:00
|
|
|
|
2012-10-17 00:54:46 +02:00
|
|
|
static void __bionic_format_dlerror(const char* msg, const char* detail) {
|
|
|
|
char* buffer = __get_thread()->dlerror_buffer;
|
|
|
|
strlcpy(buffer, msg, __BIONIC_DLERROR_BUFFER_SIZE);
|
2014-08-29 21:02:36 +02:00
|
|
|
if (detail != nullptr) {
|
2012-10-17 00:54:46 +02:00
|
|
|
strlcat(buffer, ": ", __BIONIC_DLERROR_BUFFER_SIZE);
|
|
|
|
strlcat(buffer, detail, __BIONIC_DLERROR_BUFFER_SIZE);
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
2012-10-17 00:54:46 +02:00
|
|
|
|
|
|
|
__bionic_set_dlerror(buffer);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
char* __loader_dlerror() {
|
2016-08-12 00:02:45 +02:00
|
|
|
char* old_value = __bionic_set_dlerror(nullptr);
|
2012-10-17 00:54:46 +02:00
|
|
|
return old_value;
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
|
2014-05-14 19:02:03 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2014-01-14 01:37:47 +01:00
|
|
|
do_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
|
2014-05-14 19:02:03 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2012-12-20 23:42:14 +01:00
|
|
|
do_android_update_LD_LIBRARY_PATH(ld_library_path);
|
|
|
|
}
|
|
|
|
|
2016-11-23 01:55:25 +01:00
|
|
|
static void* dlopen_ext(const char* filename,
|
|
|
|
int flags,
|
|
|
|
const android_dlextinfo* extinfo,
|
|
|
|
const void* caller_addr) {
|
2014-05-14 19:02:03 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2016-07-12 03:11:39 +02:00
|
|
|
g_linker_logger.ResetState();
|
2016-03-24 23:30:30 +01:00
|
|
|
void* result = do_dlopen(filename, flags, extinfo, caller_addr);
|
2014-08-29 21:02:36 +02:00
|
|
|
if (result == nullptr) {
|
2013-03-06 03:47:58 +01:00
|
|
|
__bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
|
2014-08-29 21:02:36 +02:00
|
|
|
return nullptr;
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void* __loader_android_dlopen_ext(const char* filename,
|
2016-11-23 01:55:25 +01:00
|
|
|
int flags,
|
|
|
|
const android_dlextinfo* extinfo,
|
|
|
|
const void* caller_addr) {
|
2015-07-17 19:36:10 +02:00
|
|
|
return dlopen_ext(filename, flags, extinfo, caller_addr);
|
2014-05-20 00:06:58 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void* __loader_dlopen(const char* filename, int flags, const void* caller_addr) {
|
2015-07-17 19:36:10 +02:00
|
|
|
return dlopen_ext(filename, flags, nullptr, caller_addr);
|
2014-02-06 15:34:21 +01:00
|
|
|
}
|
|
|
|
|
2016-11-23 01:55:25 +01:00
|
|
|
void* dlsym_impl(void* handle, const char* symbol, const char* version, const void* caller_addr) {
|
2014-05-14 19:02:03 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2016-07-12 03:11:39 +02:00
|
|
|
g_linker_logger.ResetState();
|
2015-12-11 01:08:14 +01:00
|
|
|
void* result;
|
2015-12-11 23:22:24 +01:00
|
|
|
if (!do_dlsym(handle, symbol, version, caller_addr, &result)) {
|
2015-12-11 01:08:14 +01:00
|
|
|
__bionic_format_dlerror(linker_get_error_buffer(), nullptr);
|
2014-08-29 21:02:36 +02:00
|
|
|
return nullptr;
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
|
|
|
|
2015-12-11 01:08:14 +01:00
|
|
|
return result;
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr) {
|
2015-12-11 23:22:24 +01:00
|
|
|
return dlsym_impl(handle, symbol, nullptr, caller_addr);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void* __loader_dlvsym(void* handle, const char* symbol, const char* version, const void* caller_addr) {
|
2015-12-11 23:22:24 +01:00
|
|
|
return dlsym_impl(handle, symbol, version, caller_addr);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
int __loader_dladdr(const void* addr, Dl_info* info) {
|
2014-05-14 19:02:03 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2015-12-11 01:08:14 +01:00
|
|
|
return do_dladdr(addr, info);
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
int __loader_dlclose(void* handle) {
|
2014-05-14 19:02:03 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2016-03-24 23:30:30 +01:00
|
|
|
int result = do_dlclose(handle);
|
|
|
|
if (result != 0) {
|
|
|
|
__bionic_format_dlerror("dlclose failed", linker_get_error_buffer());
|
|
|
|
}
|
|
|
|
return result;
|
2012-10-12 01:08:51 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
int __loader_dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
|
2015-06-29 23:48:25 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
return do_dl_iterate_phdr(cb, data);
|
|
|
|
}
|
|
|
|
|
2016-11-23 01:55:25 +01:00
|
|
|
#if defined(__arm__)
|
2017-08-29 18:14:49 +02:00
|
|
|
_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
|
2016-11-23 01:55:25 +01:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
return do_dl_unwind_find_exidx(pc, pcount);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-13 01:01:37 +01:00
|
|
|
void __loader_android_set_application_target_sdk_version(int target) {
|
2015-05-28 03:29:41 +02:00
|
|
|
// lock to avoid modification in the middle of dlopen.
|
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2015-05-22 02:43:49 +02:00
|
|
|
set_application_target_sdk_version(target);
|
|
|
|
}
|
|
|
|
|
2018-11-13 01:01:37 +01:00
|
|
|
int __loader_android_get_application_target_sdk_version() {
|
2015-05-22 02:43:49 +02:00
|
|
|
return get_application_target_sdk_version();
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*)) {
|
2016-07-21 20:33:40 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
get_dlwarning(obj, f);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
bool __loader_android_init_anonymous_namespace(const char* shared_libs_sonames,
|
|
|
|
const char* library_search_path) {
|
2015-10-30 01:01:24 +01:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2017-02-03 23:07:34 +01:00
|
|
|
bool success = init_anonymous_namespace(shared_libs_sonames, library_search_path);
|
2015-10-30 01:01:24 +01:00
|
|
|
if (!success) {
|
2017-02-03 23:07:34 +01:00
|
|
|
__bionic_format_dlerror("android_init_anonymous_namespace failed", linker_get_error_buffer());
|
2015-10-30 01:01:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
android_namespace_t* __loader_android_create_namespace(const char* name,
|
2016-11-23 01:55:25 +01:00
|
|
|
const char* ld_library_path,
|
|
|
|
const char* default_library_path,
|
|
|
|
uint64_t type,
|
|
|
|
const char* permitted_when_isolated_path,
|
|
|
|
android_namespace_t* parent_namespace,
|
|
|
|
const void* caller_addr) {
|
2015-10-30 01:01:24 +01:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
|
2016-05-13 00:20:21 +02:00
|
|
|
android_namespace_t* result = create_namespace(caller_addr,
|
|
|
|
name,
|
|
|
|
ld_library_path,
|
|
|
|
default_library_path,
|
|
|
|
type,
|
|
|
|
permitted_when_isolated_path,
|
|
|
|
parent_namespace);
|
2015-10-30 01:01:24 +01:00
|
|
|
|
|
|
|
if (result == nullptr) {
|
|
|
|
__bionic_format_dlerror("android_create_namespace failed", linker_get_error_buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
bool __loader_android_link_namespaces(android_namespace_t* namespace_from,
|
|
|
|
android_namespace_t* namespace_to,
|
|
|
|
const char* shared_libs_sonames) {
|
2017-02-03 23:07:34 +01:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
|
|
|
|
bool success = link_namespaces(namespace_from, namespace_to, shared_libs_sonames);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
__bionic_format_dlerror("android_link_namespaces failed", linker_get_error_buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-01-18 05:05:09 +01:00
|
|
|
bool __loader_android_link_namespaces_all_libs(android_namespace_t* namespace_from,
|
|
|
|
android_namespace_t* namespace_to) {
|
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
|
|
|
|
bool success = link_namespaces_all_libs(namespace_from, namespace_to);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
__bionic_format_dlerror("android_link_namespaces_all_libs failed", linker_get_error_buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
android_namespace_t* __loader_android_get_exported_namespace(const char* name) {
|
2020-04-21 02:59:18 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2017-04-03 16:10:37 +02:00
|
|
|
return get_exported_namespace(name);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:14:49 +02:00
|
|
|
void __loader_cfi_fail(uint64_t CallSiteTypeId, void* Ptr, void *DiagData, void *CallerPc) {
|
2020-04-21 03:01:00 +02:00
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
2016-07-06 22:20:59 +02:00
|
|
|
CFIShadowWriter::CfiFail(CallSiteTypeId, Ptr, DiagData, CallerPc);
|
|
|
|
}
|
|
|
|
|
2018-01-05 11:39:28 +01:00
|
|
|
void __loader_add_thread_local_dtor(void* dso_handle) {
|
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
increment_dso_handle_reference_counter(dso_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __loader_remove_thread_local_dtor(void* dso_handle) {
|
|
|
|
ScopedPthreadMutexLocker locker(&g_dl_mutex);
|
|
|
|
decrement_dso_handle_reference_counter(dso_handle);
|
|
|
|
}
|
|
|
|
|
2018-11-22 11:40:17 +01:00
|
|
|
libc_shared_globals* __loader_shared_globals() {
|
|
|
|
return __libc_shared_globals();
|
|
|
|
}
|
|
|
|
|
Add the recoverable GWP-ASan feature.
GWP-ASan's recoverable mode was landed upstream in
https://reviews.llvm.org/D140173.
This mode allows for a use-after-free or a buffer-overflow bug to be
detected by GWP-ASan, a crash report dumped, but then GWP-ASan (through
the preCrashReport() and postCrashReportRecoverableOnly() hooks) will
patch up the memory so that the process can continue, in spite of the
memory safety bug.
This is desirable, as it allows us to consider migrating non-system apps
from opt-in GWP-ASan to opt-out GWP-ASan. The major concern was "if we
make it opt-out, then bad apps will start crashing". If we don't crash,
problem solved :). Obviously, we'll need to do this with an amount of
process sampling to mitigate against the 70KiB memory overhead.
The biggest problem is that the debuggerd signal handler isn't the first
signal handler for apps, it's the sigchain handler inside of libart.
Clearly, the sigchain handler needs to ask us whether the crash is
GWP-ASan's fault, and if so, please patch up the allocator. Because of
linker namespace restrictions, libart can't directly ask the linker
(which is where debuggerd lies), so we provide a proxy function in libc.
Test: Build the platform, run sanitizer-status and various test apps
with recoverable gwp-asan. Assert that it doesn't crash, and we get a
debuggerd report.
Bug: 247012630
Change-Id: I86d5e27a9ca5531c8942e62647fd377c3cd36dfd
2023-01-19 21:47:22 +01:00
|
|
|
bool __loader_android_handle_signal(int signal_number, siginfo_t* info, void* context) {
|
|
|
|
return debuggerd_handle_signal(signal_number, info, context);
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:14:03 +02:00
|
|
|
static uint8_t __libdl_info_buf[sizeof(soinfo)] __attribute__((aligned(8)));
|
|
|
|
static soinfo* __libdl_info = nullptr;
|
2013-10-05 02:01:33 +02:00
|
|
|
|
2014-05-09 18:10:14 +02:00
|
|
|
// This is used by the dynamic linker. Every process gets these symbols for free.
|
2019-06-05 05:56:56 +02:00
|
|
|
soinfo* get_libdl_info(const soinfo& linker_si) {
|
2017-08-29 18:14:49 +02:00
|
|
|
CHECK((linker_si.flags_ & FLAG_GNU_HASH) != 0);
|
|
|
|
|
2015-03-31 20:14:03 +02:00
|
|
|
if (__libdl_info == nullptr) {
|
2019-06-05 05:56:56 +02:00
|
|
|
__libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, nullptr, nullptr, 0, 0);
|
2017-08-29 18:14:49 +02:00
|
|
|
__libdl_info->flags_ |= (FLAG_LINKED | FLAG_GNU_HASH);
|
|
|
|
__libdl_info->strtab_ = linker_si.strtab_;
|
|
|
|
__libdl_info->symtab_ = linker_si.symtab_;
|
|
|
|
__libdl_info->load_bias = linker_si.load_bias;
|
2018-08-21 02:44:42 +02:00
|
|
|
__libdl_info->phdr = linker_si.phdr;
|
|
|
|
__libdl_info->phnum = linker_si.phnum;
|
2017-08-29 18:14:49 +02:00
|
|
|
|
|
|
|
__libdl_info->gnu_nbucket_ = linker_si.gnu_nbucket_;
|
|
|
|
__libdl_info->gnu_maskwords_ = linker_si.gnu_maskwords_;
|
|
|
|
__libdl_info->gnu_shift2_ = linker_si.gnu_shift2_;
|
|
|
|
__libdl_info->gnu_bloom_filter_ = linker_si.gnu_bloom_filter_;
|
|
|
|
__libdl_info->gnu_bucket_ = linker_si.gnu_bucket_;
|
|
|
|
__libdl_info->gnu_chain_ = linker_si.gnu_chain_;
|
|
|
|
|
2015-03-31 20:14:03 +02:00
|
|
|
__libdl_info->ref_count_ = 1;
|
2017-08-29 18:14:49 +02:00
|
|
|
__libdl_info->strtab_size_ = linker_si.strtab_size_;
|
2015-03-31 20:14:03 +02:00
|
|
|
__libdl_info->local_group_root_ = __libdl_info;
|
2021-01-13 08:09:10 +01:00
|
|
|
__libdl_info->soname_ = linker_si.soname_;
|
2015-06-03 02:36:54 +02:00
|
|
|
__libdl_info->target_sdk_version_ = __ANDROID_API__;
|
2016-03-24 23:30:30 +01:00
|
|
|
__libdl_info->generate_handle();
|
2015-10-20 20:06:25 +02:00
|
|
|
#if defined(__work_around_b_24465209__)
|
2021-01-11 18:04:58 +01:00
|
|
|
strlcpy(__libdl_info->old_name_, __libdl_info->soname_.c_str(),
|
|
|
|
sizeof(__libdl_info->old_name_));
|
2015-03-31 20:14:03 +02:00
|
|
|
#endif
|
2014-05-09 18:10:14 +02:00
|
|
|
}
|
2012-10-12 01:08:51 +02:00
|
|
|
|
2015-03-31 20:14:03 +02:00
|
|
|
return __libdl_info;
|
2014-05-09 18:10:14 +02:00
|
|
|
}
|