Commit graph

22 commits

Author SHA1 Message Date
Mitch Phillips
a493fe4153 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-02-02 15:35:25 -08:00
dimitry
ce584e4fc9 Fix CtsJniTestCases
The linker_namespaces test need android_get_LD_LIBRARY_PATH function.

Bug: http://b/129479780
Test: atest CtsJniTestCases
Change-Id: Iba5f74e1e4b5b1de173150120293102524db2507
(cherry picked from commit 91b0c68009)
2019-04-01 13:17:20 +02:00
dimitry
8868d9e900 Move platform-private symbols out of libdl.so
Symbols not intended to be accessible from apps are moved to libdl_android.so

Test: bionic-unit-tests
Bug: http://b/129387775
Change-Id: Ib8ba6147a20cf56550c9a008f66570a2d419565a
(cherry picked from commit 2d6be9a751)
2019-04-01 13:16:33 +02:00
Jiyong Park
c45fe9f7bd Add stubs variants for bionic libs
Bionic libs are part of the runtime APEX (com.android.runtime). In order
to be able to update the runtime APEX independetly from the platform, we
have to prevent things outside of the APEX from using bionic symbols
that are not guaranteed to be stable. Otherwise, platform could break
when a symbol is removed from the libs via the APEX update.

To achive this goal, this change adds stubs variant to the bionic libs.
With this, things outside of the runtime APEX (i.e. other APEXes and the
platform) are built with the stubs variants that provide only the
symbols that are guaranteed to be stable.

The set of symbols are basically the same as the symbols available to
NDK clients. However, there are a few additional symbols that are not
available for NDK but should be made available for platform components.
They are marked with "# apex" tag. Symbols with that tag are not exposed
to apps (via NDK stubs) or vendors (via LLNDK stubs).

Note that the stubs is a build-time only artifact. It is used just to
break the build when private symbols are used outside of the runtime
APEX. At runtime, the real library in the APEX is used.

Bug: 120266448
Test: m
Test: m bionic-unit-tests
Change-Id: I7b8d75830c81d7d7d54e2fca21a85b3417531b47
2019-01-04 22:29:36 +09:00
Elliott Hughes
c0f4656452 Make android_get_application_target_sdk_version available to the NDK.
Also move this and android_get_device_api_level into <android/api-level.h>
so that they're always available.

This involves cleaning up <sys/cdefs.h> slightly.

Bug: N/A
Test: builds
Change-Id: I25435c55f3549cd0d827a7581bee75ea8228028b
2018-11-15 11:07:30 -08:00
dimitry
321476a3ec Test ld-android.so directly
This CL addresses review comments from
https://android-review.googlesource.com/c/platform/bionic/+/595067

Test: bionic-unit-tests --gtest_filter=dl*
Change-Id: I2c0fdf2a89fe6ff134308e202fb99a74080ee0ed
2018-01-29 15:32:37 +01:00
Logan Chien
9ee4591cb4 linker: Allow link namespaces without name filters
This commit allows users to create a link without soname filters between
two linker namespaces.

The motivation is to establish one-way shared library isolation.  For
example, assume that there are two linker namespaces `default` and
`vndk`.  We would like to limit the shared libraries that can be used by
the `default` namespace.  In the meanwhile, we would like to allow the
`vndk` namespace to use shared libs from the `default` namespace if the
soname cannot be find in the search path or loaded sonames of the `vndk`
namespace.

          shared_libs  = %VNDK_CORE_LIBRARIES%
          shared_libs += %VNDK_SAMEPROCESS_LIBRARIES%
    vndk <-------------------------------------------- default
       \_______________________________________________/^
                allow_all_shared_libs = true

android_link_namespaces_all_libs() is added to libdl, but it is
versioned as LIBC_PRIVATE.  android_link_namespaces_all_libs() is only
for unit tests.

Bug: 69824336

Test: adb shell /data/nativetest/linker-unit-tests/linker-unit-tests32
Test: adb shell /data/nativetest64/linker-unit-tests/linker-unit-tests64

Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
Test: adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests

Test: Update /system/etc/ld.config*.txt and check whether the vndk
linker namespace of the vendor process can access the shared libs from
the default linker namespace.

Change-Id: I2879f0c5f5af60c7e56f8f743ebd2872e552286b
2018-01-25 14:45:29 +08:00
Elliott Hughes
a5c316fe0c Don't repeat ourselves unnecessarily in the maps.
We can mark a whole version "introduced=" rather than doing every line
separately.

Bug: N/A
Test: builds
Change-Id: I3219edc755a42ce5ff6258efb744fb5e05967a3a
2017-10-02 10:10:15 -07:00
Jiyong Park
8664a05637 Fix API level of cfi_* symbols to 27
API level of O-MR1 is 27.

Bug: 63053790
Test: bionic tests passes

Change-Id: I78f0bd8af106954326394d60bf4d0cf5e10f7f17
2017-10-02 08:15:34 -07:00
Evgenii Stepanov
97c16f8dca [cfi] Export __cfi_shadow_size.
__cfi_shadow_size returns the size of the CFI shadow mapping, or 0 if
CFI is not (yet) used in this process. This can be used to adjust
RLIMIT_AS setting.

Test: device bionic tests
Bug: 64293803
Change-Id: Icd7164f96aa7115b3585c21c0f68529cd2f07c11
2017-08-03 14:04:15 -07:00
Jiyong Park
f1cee9662f __cfi_slowpath[_diag] are available to NDK and VNDK clients
When a vendor lib (or vendor-available platform lib) is built with
sanitizer on, __cfi_slowpath_diag is required. However, when building
for those libs, the llndk stub of libdl.so is provided for them and
__cfi_slowpath_diag is not exposed to the stub. In order to make the
sanitizing build successful, expose the symbol.

These symbols are also exposed to NDK clients since we may want to CFI
for unbundled apps.

Bug: 63053790
Bug: 63342219
Test: BOARD_VNDK_VERSION=current m -j libstagefright_foundation.vendor

Change-Id: I081deddb4f66354aaecec4b395d4e17e5566c578
2017-07-13 10:18:56 +09:00
Jiyong Park
01de74e76d linker: add android_get_exported_namespace
Depending on how ld.config.txt is configured, there can be multiple
built-in namespaces created by the linker from the beginning of a
process. android_get_exported_namespace is a platform only API for
getting a handle (android_namespace_t*) to one of the built-in namespaces
with given name. The returned namespace can then be given to
android_dlopen_ext in order to explicitly specify the target namespace
where the library is searched and loaded from.

Note that this function only returns 'exported' namespaces created via
ld.config.txt file. In order to export a namespace, the visible property
should be set to true:

namespace.<name>.visible = true

Namespaces are hidden by default. Hidden namespaces and namespaces
that are created programmatically, notably 'classloader-namespace',
aren't returned by this function.

Bug: 36851137
Test: confirmed that namespaces created with ld.config.txt is retrieved.
Test: linker-unit-tests passes
Merged-in: I714b510fa24f77e42c3dfc4c827b3befa8bb2951
Change-Id: I0d05fa7e0e116009edf8ea362ab46774bc617cbf
(cherry picked from commit d7c4832e6a)
2017-04-28 10:14:28 +09:00
Dimitry Ivanov
7a34b9d57a Replace public library list with shared lib sonames (part 2/2)
This commit updates interface of libdl.c.

1. android_init_namespaces is replaces with android_init_anonymous_namespace
2. added 2 arguments to android_create_namespace to specify linked namespace
   and the list of shared libraries sonames.
3. symbol lookup does not get past boundary libraries (added check and test for it).

Bug: http://b/26833548
Bug: http://b/21879602
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I32921da487a02e5bd0d2fc528904d1228394bfb9
2017-02-09 23:26:44 -08:00
Evgenii Stepanov
0a3637d3eb Runtime support for CFI
Control Flow Integrity support in bionic.

General design:
http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html#shared-library-support

This CL implements subsections "CFI Shadow" and "CFI_SlowPath" in the above document.

Bug: 22033465
Test: bionic device tests
Change-Id: I14dfea630de468eb5620e7f55f92b1397ba06217
2017-01-18 13:13:52 -08:00
Dan Albert
1bcaf53d20 Annotate libdl.map.txt.
Test: readelf diff between soong generated stubs and prebuilts/ndk
Bug: http://b/30465923
Change-Id: Ic34734b40870c8b628449458798c0343648e4e97
2016-08-04 13:43:20 -07:00
Dimitry Ivanov
769b33fadf Sync linker with internal branch
This change includes dlwarning implementation and
the compatibility greylist for apps targeting pre-N.

Change-Id: Ibf02a07cc58cbbb1a5aef4ac34558c5d43e4305f
Test: Run bionic-unit-tests --gtest_filter=dl*:Dl*
2016-08-01 19:47:27 +00:00
Dimitry Ivanov
7a622dacf1 Move linker-namespace functions to LIBC_PLATFORM
Bug: http://b/28174921
Change-Id: I089dbeeea813fc2128b9c2f6268a578d23a1954a
(cherry picked from commit 7095da8d3c)
2016-04-13 16:41:31 -07:00
Dimitry Ivanov
98cdef39dc libdl: Rename LIBC_PRIVATE to LIBC_PLATFORM
Bug: http://b/26386014
Change-Id: I3255faac66a96867aed302e205e3644b40ce7750
2016-03-02 11:41:22 -08:00
Dimitry Ivanov
9cf99cbad8 linker: add dlvsym(3)
This changes implements dlvsym - dlsym for versioned symbols.

Bug: http://b/22865643
Change-Id: Ic90a60d512104261a1416c43f9100f0d88e3b46f
2015-12-16 15:24:13 -08:00
Dmitriy Ivanov
1ffec1cc4d Introduce anonymous namespace
The anonymous namespace is introduced to
handle cases when linker can not find the
caller. This usually happens when caller
code was not loaded by dynamic linker;
for example mono-generated code.

Bug: http://b/25844435
Bug: http://b/22548808
Change-Id: I9e5b1d23c1c75bc78548d68e79216a6a943a33cf
2015-11-23 16:13:10 -08:00
Dmitriy Ivanov
42d5fcb9f4 Introducing linker namespaces
Bug: http://b/22548808
Change-Id: Ia3af3c0a167f1d16447a3d83bb045d143319b1e1
2015-11-15 12:09:16 -08:00
Dmitriy Ivanov
bc75047a1b Generate libdl.so per-architecture version script
Bug: http://b/24767418
Change-Id: I3d5775ba44d4c8e7fc5f2fbebae10e022100f1e2
2015-10-30 17:43:27 -07:00
Renamed from libdl/libdl.map (Browse further)