Commit graph

541 commits

Author SHA1 Message Date
dimitry
6e6772dcb2 Remove libskia.so from the greylist
The library is no longer available on the devices.

Bug: http://b/31971097
Test: make
Change-Id: Ie87bb8a8c200d086d272ca923242bfbab6397126
2018-05-25 10:37:49 +02:00
Logan Chien
bcfe3cf06e Use ro.vndk.lite to determine the ld.config.txt
This commit adds an extra check on `ro.vndk.lite`.  If `ro.vndk.lite` is
true, the linker will pick `/system/etc/ld.config.vndk_lite.txt`.

The purpose of this change is to distinguish:

1. Master-GSI + Master-VENDOR (w/o BOARD_VNDK_VERSION for upgrading devices)
2. Master-GSI + O-MR1-VENDOR (w/ BOARD_VNDK_VERSION)

Bug: 78605339
Test: aosp_sailfish Master-SYSTEM + Master-VENDOR boots
Test: aosp_sailfish Master-GSI    + Master-VENDOR boots
Test: aosp_walleye  Master-SYSTEM + Master-VENDOR boots
Test: aosp_walleye  Master-GSI    + Master-VENDOR boots
Test: aosp_walleye  Master-GSI    + O-MR1-VENDOR boots
Change-Id: I34f243f73c173ca2e882d3738ccb81e3fad3a9da
Merged-In: I34f243f73c173ca2e882d3738ccb81e3fad3a9da
(cherry picked from commit dd18472e56)
2018-05-17 14:27:00 +08:00
Logan Chien
886b96ef9a Extract ld.config.txt lookup code
This commit extracts ld.config.txt lookup code into
`get_ld_config_file_path()`.

Bug: 78605339
Test: aosp_walleye-userdebug builds and boots
Change-Id: I129f19cd032de02a56bda57231521c02a4b4e4c0
Merged-In: I129f19cd032de02a56bda57231521c02a4b4e4c0
(cherry picked from commit 21e496cf29)
2018-05-17 14:26:54 +08:00
dimitry
8b142566e3 vdso should be available in all namespaces
vdso should be available in all namespaces when present. This
bug went undetected because the way libc currently uses vdso (it
does all the lookups itself). This makes it available for the
programs that want to take advantage by dlopening it.

Bug: http://b/73105445
Bug: http://b/79561555
Test: adb shell /data/nativetest/arm/bionic-unit-tests/bionic-unit-tests --gtest_filter=dl.exec_with_ld_config_file
Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests --gtest_filter=dl*
Change-Id: I8eae0c9848f256190d1c9ec85d10dc6ce383a8bc
(cherry picked from commit 69c68c46ac)
2018-05-12 10:58:00 +02:00
Elliott Hughes
c01b849c9a Remove obsolete workaround.
We removed the cast in question in
d390df1dbc.

Bug: N/A
Test: builds
Change-Id: I56a034432fd11aeca00c09cb11226bdae465366f
2018-05-09 09:54:30 -07:00
Elliott Hughes
9724e93c19 Reject .so files using ELF TLS.
Bug: http://b/74361956
Test: ran tests
Change-Id: I53e71252eb08c607c2c436dcba433374c8c53887
2018-03-23 18:46:07 -07:00
Elliott Hughes
9076b0c4e7 Be clearer about linker warnings.
Explicitly say "warning" for warnings, explicitly say what action
we're going to take (such as "(ignoring)"), always provide a link to
our documentation when there is one, explicitly say what API level the
behavior changes at, and explicitly say why we're allowing the misbehavior
for now.

Bug: http://b/71852862
Test: ran tests, looked at logcat
Change-Id: I1795a5af45deb904332b866d7d666690dae4340b
2018-02-28 12:37:28 -08:00
dimitry
153168c855 Fix RTLD_NEXT/DEFAULT lookup
RTLD_NEXT/DEFAULT lookup should not skip handle lookup
in the case when the load group is RTLD_GLOBAL.

Note that there is a difference between load group is local group.
The local group includes externally referenced libraries where
the load group does not. The external reference in this context is a
DT_NEEDED library that belongs to a previously loaded group.

Bug: http://b/72237367
Test: bionic-unit-tests --gtest_filter=dl*
Change-Id: I8997cc961c13a5396f1756161798b45ed1cab16c
2018-02-20 17:10:00 +01:00
Treehugger Robot
2e2a8930e5 Merge "linker: simpler encoding for SHT_RELR sections." 2018-01-27 00:00:17 +00:00
Rahul Chaudhry
f16b65932b linker: simpler encoding for SHT_RELR sections.
This change modifies the encoding used in SHT_RELR sections to a simpler
version that gives better results. This encoding was suggested by Andrew
Grieve and is described in this post on generic-abi@googlegroups.com:
    https://groups.google.com/d/msg/generic-abi/bX460iggiKg/Pi9aSwwABgAJ

Bug: None
Test: Built image for marlin, flashed on device, ran arm and
      aarch64 binaries containing '.relr.dyn' sections using
      the new encoding.

Change-Id: I266affe0fbad91dc375995985a221cb02499447b
2018-01-26 11:46:47 -08: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
d00d38b36b Merge "linker: add experimental support for SHT_RELR sections." 2018-01-23 00:24:26 +00:00
Rahul Chaudhry
b7feec7454 linker: add experimental support for SHT_RELR sections.
This change adds experimental support for SHT_RELR sections, proposed
here: https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg

Definitions for the new ELF section type and dynamic array tags, as well
as the encoding used in the new section are all under discussion and are
subject to change. Use with caution!

Bug: None
Test: Built image for marlin, flashed on device, ran arm and
      aarch64 binaries containing '.relr.dyn' sections.

Change-Id: I2953ae932d3c42ae394e71f8fa058013758a1778
2018-01-22 12:41:27 -08:00
Elliott Hughes
5cec377f49 Address a bunch of clang-tidy complaints.
There were a bunch more unreasonable/incorrect ones, but these ones
seemed legit. Nothing very interesting, though.

Bug: N/A
Test: ran tests, benchmarks
Change-Id: If66971194d4a7b4bf6d0251bedb88e8cdc88a76f
2018-01-19 15:56:12 -08:00
dimitry
06016f226e Fix dlclose for libraries with thread_local dtors
Introduce new flag to mark soinfo as TLS_NODELETE when
there are thread_local dtors associated with dso_handle
belonging to it.

Test: bionic-unit-tests --gtest_filter=dl*
Test: bionic-unit-tests-glibc --gtest_filter=dl*
Bug: https://github.com/android-ndk/ndk/issues/360
Change-Id: I724ef89fc899788f95c47e6372c38b3313f18fed
2018-01-10 10:24:06 +01:00
dimitry
965d06da1e Fix logic in loading dependencies crossing namespace boundaries
This change addresses multiple problems introduced by
02586a2a34

1. In the case of unsuccessful dlopen the failure guard is triggered
for two namespaces which leads to double unload.

2. In the case where load_tasks includes libraries from 3 and more
namespaces it results in incorrect linking of libraries shared between
second and third/forth and so on namespaces.

The root cause of these problems was recursive call to find_libraries.
It does not do what it is expected to do. It does not form new load_tasks
list and immediately jumps to linking local_group. Not only this skips
reference counting it also will include unlinked but accessible library
from third (and fourth and fifth) namespaces in invalid local group. The
best case scenario here is that for 3 or more namesapces this will
fail to link. The worse case scenario it will link the library
incorrectly with will lead to very hard to catch bugs.

This change removes recursive call and replaces it with explicit list of
local_groups which should be linked. It also revisits the way we do
reference counting - with this change the reference counts are updated after
after libraries are successfully loaded.

Also update soinfo_free to abort in case when linker tries to free same
soinfo for the second time - this makes linker behavior less undefined.

Test: bionic-unit-tests
Bug: http://b/69787209
Change-Id: Iea25ced181a98c6503cce6e2b832c91d697342d5
2017-12-10 22:04:55 +01:00
Alin Jerpelea
816b259880 Merge "linker: add support for odm partition"
am: 7b5073767d

Change-Id: I0c1356f53cd33e0cd6a78f0798fed8b395893859
2017-12-06 04:09:37 +00:00
Treehugger Robot
7b5073767d Merge "linker: add support for odm partition" 2017-12-06 04:03:07 +00:00
Justin Yun
bf9cf750a4 Merge "Use ld.config.$VER.txt when current VNDK version is $VER"
am: 86a3803799

Change-Id: I350a75a183717e3cd0a68d3a9ed524f19f077a2f
2017-12-03 14:32:36 +00:00
Justin Yun
53ce74288c Use ld.config.$VER.txt when current VNDK version is $VER
When ro.vndk.version is set to a specific version, not "current",
use ld.config.$VER.txt as a linker namespace configuration file,
where $VER is the VNDK version set by ro.vndk.version.

Because ro.vndk.version is set by the vendor partition, the
configuration file will be automatically selected by the VNDK version
of vendor patition.

If ro.vndk.version is current or not set, ld.config.txt will be used
as before.

Bug: 69531793
Test: Build for a Pixel2 device.
  In the out/target/product/<device> directory,
    rename system/etc/ld.config.txt to system/etc/ld.config.27.1.0.txt
    rename system/lib[64]/vndk to system/lib[64]/vndk-27.1.0
    copy system/lib[64]/vndk-sp to system/lib[64]/vndk-sp-27.1.0
    set ro.vndk.version to 27.1.0 in vendor/default.prop
  Build system and vendor images with "make snod" and "make vnod".
  Disble vbmeta using avbtool.
  Flash a device and check boot.

Change-Id: Ic55bb0a741d434e5fa93e109be15df9d9de3f105
2017-12-03 23:26:53 +09:00
Alin Jerpelea
074a9fd3da linker: add support for odm partition
If libraries are on the odm partition they will fail to load
This patch adds the odm path as a search path for linker.

Test: libraries load from the odm partition
Change-Id: Ia7786e047cc565d74d25c025dacf9266b3763650
Signed-off-by: Alin Jerpelea <alin.jerpelea@son.com>
2017-12-01 06:21:17 +09:00
Elliott Hughes
65ba81b4e8 Merge "Revert "Fix bug with double unload on unsuccessful dlopen""
am: 4eb332439a

Change-Id: I21ba611931b2e5794ef49cae9bcafc8748ebe804
2017-11-29 19:34:10 +00:00
Elliott Hughes
27f1806b90 Revert "Fix bug with double unload on unsuccessful dlopen"
This reverts commit 58554ccb8a.

causes /vendor/bin/qseecomd to hit the new abort:

[    8.983301] c5    603 DEBUG: Abort message: 'soinfo=0x7147894cd0 is not in soinfo_list (double unload?)'

Bug: http://b/69909887
Bug: http://b/69787209
Change-Id: Ied38f797e0a071a1acc5ed41adf1b45e855143c7
2017-11-29 18:48:33 +00:00
Dimitry Ivanov
f1e645c67b Merge "Fix bug with double unload on unsuccessful dlopen"
am: dc89324e93

Change-Id: Ibff72e8a13cdc737d950dc71f2612fc99740109f
2017-11-29 09:37:01 +00:00
dimitry
58554ccb8a Fix bug with double unload on unsuccessful dlopen
In the case of unsuccessful dlopen the failure guard is triggered
for two namespaces which leads to double unload.

Also update soinfo_free to abort in case when linker tries to free same
soinfo for the second time - this makes linker behavior less undefined.

Test: bionic-unit-tests
Bug: http://b/69787209
Change-Id: I886787ee021b050667f967bce7aa2708390886ea
2017-11-28 21:47:01 +01:00
Xin Li
74d57a37cb Merge commit 'e3d21c84af0b8e3244e4c67a873d2a16bfb85034' into HEAD
Change-Id: I09b21c2e27a0dfbef10633b20d8ee7adbedc1597
2017-11-14 13:14:23 -08:00
dimitry
c92ce715c5 Log dlclose calls and library unloads
Bug: http://b/29458203
Bug: http://b/68262627
Test: make && run bionic-unit-tests
Test: set debug.ld.all to dlopen and check the logs
Change-Id: I9a5495843a4145f267cc3a4714294d05b1e1fe90
2017-10-27 15:38:15 +02:00
dimitry
8db36a51ff linker: fix error message for inaccessible libs
Added a test to make sure linker produces correct error message
when user attempts to load a library in a linked namespace and fails.

Bug: http://b/67866190
Bug: http://b/64950640
Bug: http://b/64888291
Test: bionic-unit-test --gtest_filter=dlext*
Change-Id: I5b5c2070d1388eff123118350b2b5c8fc7571a29
2017-10-23 15:14:01 +02:00
Jiyong Park
01162f2469 Fix: linker segfault on dlopen of a DF_1_GLOBAL so
Added the missing null check routine.

Bug: 67755729
Test: dlfcn.dlopen_df_1_global added and it passes
Change-Id: Ibe8db18b0b5a481e2e9937041abef6d6b179dd87
2017-10-19 15:13:54 +09:00
Dan Willemsen
39b65475d9 Merge changes from topic "host_bionic" am: 6e6e1abb89 am: 9938cdeee8
am: 23ec4fd7e6

Change-Id: Ieb803f66f1f0f7bd29fea16df7e48f3c0195e3bf
2017-09-21 00:56:16 +00:00
Dan Willemsen
7ccc50d2e4 Use an embedded linker for host bionic
The linux kernel requires that the ELF interpreter (runtime linker)
that's referenced by PT_INTERP be either an absolute path, or a relative
path from the current working directory. We'd prefer a relative path
from the binary, similarly to how we handle looking up shared libraries,
but that's not supported.

Instead, extract the LOAD segments from the runtime linker ELF binary
and embed them into each host bionic binary, omitting the PT_INTERP
declaration. The kernel will treat it as a static binary, and we'll use
a special entry point (linker_wrapper) to fix up the arguments passed by
the kernel before jumping to the embedded linker. From the linker's
point of view, it looks like the kernel loaded the linker like normal.

Bug: 31559095
Test: Enable host bionic, build and run libdemangle_test
Change-Id: I1753401ef91eecbf0ae3376faca31eec1c53842b
2017-09-20 13:59:13 -07:00
Elliott Hughes
f810219ce7 Merge "Always log errno when aborting." am: 0c9ea17e0c am: 002b30843b
am: 5d1cf56ce5

Change-Id: I1999c656307aea0a0a0372248d65a05657546e59
2017-09-18 21:44:57 +00:00
Elliott Hughes
7b0af7ad82 Always log errno when aborting.
(Where errno is relevant.)

Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter,
but it's more common, and potentially more intention-revealing.)

Bug: http://b/65608572
Test: ran tests
Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
2017-09-15 16:18:49 -07:00
Elliott Hughes
4fde457022 Merge "Explicitly name DT_RPATH." am: e0e2798f11 am: e68ca24650
am: 1b64c2c4f0

Change-Id: I59b094b9a1c76d77f01f8a25102b3e0a6dc6f257
2017-08-30 20:03:08 +00:00
Elliott Hughes
6eae4cc57b Explicitly name DT_RPATH.
The specific case of finding a DT_RPATH entry is a pretty common harmless
warning. An alternative to this change would be to just add a case to the
switch for DT_RPATH to just silently ignore it, since it's never been
supported and is deprecated anyway.

Bug: N/A
Test: builds
Change-Id: I01986da8f1f8d411fc2ea32d492c53b9f4488c72
2017-08-30 09:02:33 -07:00
Dimitry Ivanov
5050503a5a Merge "Add support of architecture specific ld.configs" am: 506f3f11f1 am: bfec477beb
am: 595ac73b12

Change-Id: Id5e8ddaf0b6cbabf3973fa5601e0531e6d7739a0
2017-08-24 09:50:23 +00:00
dimitry
fe1b27cf84 Add support of architecture specific ld.configs
Prefer architecture specific ld.config.<arch>.txt if it exists;
fall back to default ld.config.txt files if arch-specific one is
not present.

Bug: http://b/64061157
Test: bionic-unit-tests && linker-unit-tests
Change-Id: I83a298a932f2e4af7acb2049a7641fb86908736c
2017-08-23 10:47:07 +02:00
Justin Yun
3396d1616f Merge "Make default namespace handle the 'visible' flag." am: f2c203f188 am: 01a2910758 am: 897b6dabef
am: 07cdf5e9a6

Change-Id: Ib56be3f3b4ad716dc023be3cfec531afe29246bb
2017-08-16 17:58:18 +00:00
Justin Yun
90de9f081e Make default namespace handle the 'visible' flag.
'visible' flag was interpreted only the namespaces other than 'default'.
The flag has to be handled without exception once it is set.

Bug: 63411330
Test: Build and boot without errors.
Test: Add `namespace.default.visible = true` to [vendor] process in
      'ld.config.txt' and reboot the device.

Change-Id: Ia363dfadf0200317b875e26bb4b2fae849af1384
2017-08-16 14:38:07 +09:00
Jiyong Park
d741e5ef43 Merge "linker: the global group is added to all built-in namespaces" am: c9fb66209d am: ec8c79aaa1 am: 0a51b36ad6
am: e247953f1b

Change-Id: I26521ec9cc11b9ee9ce55a61ac2bfe3152a0dd7f
2017-08-03 02:47:38 +00:00
Jiyong Park
02586a2a34 linker: the global group is added to all built-in namespaces
With ld.config.txt, we now have multiple built-in namespaces other than
the default namespace. Libs (and their dependents) listed in LD_PRELOAD
must be visible to those additional namespaces as well.

This also adds a debugging only feature: path to the linker config file
can be customized via LD_CONFIG_FILE environment variable. This works
only for debuggable builds.

Bug: 38114603
Bug: 62815515
Test: 1. ./external/compiler-rt/lib/asan/scripts/asan_device_setup --lib
prebuilts/clang/host/linux-x86/clang-stable/lib64/clang/5.0/lib/linux
2. enable talkback shortcut
3. in the home screen, hold vol-up/down together
4. device does not reboots and talkback shortcut is toggled
Test: bionic-unit-tests and linker-unit-tests successful

Change-Id: I9a03591053f4a9caea82f0dcb23e7a3d324bb9bd
2017-08-03 01:02:07 +09:00
Evgenii Stepanov
9e77a6468b Fix asan path translation loading a library twice.
An ASan binary may load a non-ASan library from /system if /data is not mounted yet.
A dlopen() call for the same library later, when /data/ is available, will translate the path and attempt to load
an ASan copy of the library from /data/asan/system. This way we may end up loading both ASan and non-ASan copies of
the library in the same process, which is a very bad thing.

This change adds a check for a loaded library with the non-translated real path before applying path translation.

Bug: 63622872
Test: hide/rename a library in /data/asan; dlopen; restore the library; dlopen; check that the library from /data/asan is NOT loaded.
Change-Id: I17060837f08dc3c665cab803dd89979d88f0a019
2017-07-27 15:02:08 -07:00
Dimitry Ivanov
fa6ebae9d9 Merge "Revert "linker: remove link from external library on unload"" into oc-dev
am: f80b2bae2f

Change-Id: Id7e4908181fb869de30676fc5c5e6abe3d24d383
2017-05-18 16:33:57 +00:00
Dimitry Ivanov
ec5ddc0a23 Revert "linker: remove link from external library on unload"
This reverts commit b37d10cc80.

Was merged from nyc-dev to master and oc-dev by mistake.

Bug: http://b/38384727
Test: bionic-unit-tests
Change-Id: I7cd352baceb3180342abb6ffec1dfa96a217961f
2017-05-18 01:02:54 +00:00
Dimitry Ivanov
5ef13ba0ca linker: remove link from external library on unload am: b37d10cc80 am: 3a644889b2 am: cb40eec87c am: 0399816edb
am: 85efd3b591

Change-Id: I115a7adb07feedf81064c0e740cfc617263eb689
2017-05-16 22:21:23 +00:00
Dimitry Ivanov
efbc04475e linker: remove link from external library on unload am: b37d10cc80 am: 3a644889b2 am: cb40eec87c am: 0399816edb
am: 85efd3b591

Change-Id: I0b41cdffdccab8b79a4d9c6327dc0f6f521c1acf
2017-05-16 22:21:22 +00:00
Dimitry Ivanov
cb40eec87c linker: remove link from external library on unload am: b37d10cc80
am: 3a644889b2

Change-Id: I7c022194739391c24a736a3a5deb906433fc5649
2017-05-16 22:12:22 +00:00
Dimitry Ivanov
3a644889b2 linker: remove link from external library on unload
am: b37d10cc80

Change-Id: I48901a8fbf4bc25fff1462e6086fc23b76ca2ba3
2017-05-16 22:08:52 +00:00
Dimitry Ivanov
b37d10cc80 linker: remove link from external library on unload
When unloading library make sure the soinfo_link to parent
from linked external libraries is removed as well.

Bug: 36104177
Bug: http://b/37433850
Test: manual
Change-Id: I601b54144acecac54744805b38313c46045c54cb
(cherry picked from commit ee398f820700de30941fd82e38bd917e1513cbc6)
2017-05-15 21:23:32 -07:00
Jiyong Park
37b91af0f3 greylist is no longer enabled by default.
greylist is needed only for application namepaces. Since we started using
linker-namesapces for vendors and other platform apps linker should not
enable greylist workaround by default.

Bug: http://b/37731053
Bug: https://issuetracker.google.com/38146125
Test: sailfish builds and boots
Test: bionic-unit-tests and linker-unit-tests pass
Change-Id: Iee83db6fb1ae754f5ade18491321d9bca3b5ead4
(cherry picked from commit e8ffe56a9c)
2017-05-09 17:59:00 -07:00
Jiyong Park
e8ffe56a9c greylist is no longer enabled by default.
greylist is needed only for application namepaces. Since we started using
linker-namesapces for vendors and other platform apps linker should not
enable greylist workaround by default.

Bug: http://b/37731053
Bug: https://issuetracker.google.com/38146125
Test: sailfish builds and boots
Test: bionic-unit-tests and linker-unit-tests pass
Change-Id: Iee83db6fb1ae754f5ade18491321d9bca3b5ead4
2017-05-08 23:22:16 -07:00
Christopher Ferris
5725481f1e Merge "Move libc_log code into libasync_safe." 2017-05-03 17:43:35 +00:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Dimitry Ivanov
f1cb669a9c Shared namespaces inherit parent ns properties
Make shared namespace inherit namespace links and
search/permitted paths from the parent namespace.

Bug: http://b/37854032
Test: bionic_unit_tests --gtest_filter=dl*:Dl*
Change-Id: I174661d4a1dd0cbe4a378179073719aa955f3592
(cherry picked from commit ec43dd6c36)
2017-05-02 16:42:28 -07:00
Dimitry Ivanov
ec43dd6c36 Shared namespaces inherit parent ns properties
Make shared namespace inherit namespace links and
search/permitted paths from the parent namespace.

Bug: http://b/37854032
Test: bionic_unit_tests --gtest_filter=dl*:Dl*
Change-Id: I174661d4a1dd0cbe4a378179073719aa955f3592
2017-05-02 11:40:50 -07:00
Treehugger Robot
87a47e1bb2 Merge "linker: add android_get_exported_namespace" 2017-05-02 01:37:04 +00: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
15f1db35fa Revert "Revert "loader: enable loading libraries from tmpfs""
This reverts commit 6d59318d78.

Bug: http://b/37245203
Bug: http://b/37590327
Test: bionic-unit-tests on angler and marlin
Test: boot an angler and make sure mediacodec does not crash
2017-04-24 13:35:41 -07:00
Yin-Chia Yeh
6d59318d78 Revert "loader: enable loading libraries from tmpfs"
This reverts commit bb8b22a087.

http://b/37245203
http://b/37590327
Change-Id: I36f45697f7478b830947d641942e453ed0d5466e
2017-04-22 23:55:41 +00:00
Dimitry Ivanov
bf34ba3641 loader: enable loading libraries from tmpfs
This change adds two tests for dlopen from temporary files.
1. One Uses memfd_create() can be used to load libraries directly
from memory. This requires relaxing namespace accessibility check
in order to make this work in isolated namespaces.
2. Another checks that open with O_TMPFILE works.

Bug: http://b/37245203
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I3be1d7198ca17e7f1ba022a0d86c64d59a493506
(cherry picked from commit bb8b22a087)
2017-04-21 14:45:07 -07:00
Dimitry Ivanov
bb8b22a087 loader: enable loading libraries from tmpfs
This change adds two tests for dlopen from temporary files.
1. One Uses memfd_create() can be used to load libraries directly
from memory. This requires relaxing namespace accessibility check
in order to make this work in isolated namespaces.
2. Another checks that open with O_TMPFILE works.

Bug: http://b/37245203
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I3be1d7198ca17e7f1ba022a0d86c64d59a493506
2017-04-21 14:37:00 -07:00
Elliott Hughes
f2c6ad6338 Make the _Unwind_Ptr declaration match clang's.
Bug: https://issuetracker.google.com/37126620
Test: builds, boots angler
Change-Id: I7d4a9b998f2e5c4c7b0beed87807d7b76a564c5c
2017-04-21 19:52:21 +00:00
Treehugger Robot
f17048bfb8 Merge "Send developers straight to the text relocation docs." 2017-04-11 06:07:07 +00:00
Elliott Hughes
763f6e108a Send developers straight to the text relocation docs.
It's been years since we allowed text relocations, but I had a developer
ask me how to fix them at last week's O Developer Day. They'd never seen
our docs, so let's try to fix that for anyone else who's still confused...

Bug: N/A
Test: builds
Change-Id: I9202a7b0a3f024041b646c43c87585f4fab22d09
2017-04-10 16:41:52 -07:00
Tom Cherry
c40af334c7 Merge "Move scopeguard into android::base" 2017-04-06 22:41:02 +00:00
Jiyong Park
d7c4832e6a 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
Change-Id: I0d05fa7e0e116009edf8ea362ab46774bc617cbf
2017-04-06 15:20:04 -07:00
Elliott Hughes
9e27e58faa Add support for disabling the greylist.
Useful for testing whether apps have actually stopped using greylisted
libraries even if they still have references to them in their apk to support
old Android releases but also haven't bumped their targetSdkVersion yet.

Since we already have two expensive __system_property_get calls and this
would add a third, optimize two (but leave the third since it's not
obviously amenable to optimization). None of this matters for user builds,
but I don't want userdebug/eng to have distractingly different performance.

(cherrypick of 7933bec2872aa1c3430149c7649726333c0ac9d8.)

Bug: http://b/36106661
Test: ran "can you escape 5" with and without this property
Change-Id: Id9a804695c1dca9b4be2ebd0e72f01817bb13cba
2017-04-06 10:59:24 -07:00
Tom Cherry
b8ab61804c Move scopeguard into android::base
Test: boot bullhead, bionic unit tests
Change-Id: I223249684867655ecb53713b10da41d3014f96ae
2017-04-05 16:37:07 -07:00
Elliott Hughes
7933bec287 Add support for disabling the greylist.
Useful for testing whether apps have actually stopped using greylisted
libraries even if they still have references to them in their apk to support
old Android releases but also haven't bumped their targetSdkVersion yet.

Since we already have two expensive __system_property_get calls and this
would add a third, optimize two (but leave the third since it's not
obviously amenable to optimization). None of this matters for user builds,
but I don't want userdebug/eng to have distractingly different performance.

Bug: http://b/36106661
Test: ran "can you escape 5" with and without this property
Change-Id: Id9a804695c1dca9b4be2ebd0e72f01817bb13cba
2017-04-05 15:35:04 -07:00
Dimitry Ivanov
dedcf35bcc Fix lookup logic for linked namespaces
When looking for already loaded libraries include
linked namespaces to the search, but check if
the library is accessible from the main namespace.

Bug: http://b/36008422
Bug: http://b/35417197
Bug: http://b/34052337
Bug: http://b/36660652
Bug: https://issuetracker.google.com/36636090
Test: run bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Ic7c1d48114da3ca5dc6512ef03f595dd17b6ed17
(cherry picked from commit d3e7d08845)
2017-04-01 19:15:32 -07:00
Treehugger Robot
6a2c7f5a68 Merge "Fix lookup logic for linked namespaces" 2017-04-02 02:14:47 +00:00
Vishwath Mohan
a782f29108 Refactor sanitized library on-disk layout - bionic.
This CL changes the linker to point to the newly refactored location
of ASAN-ified libraries on disk.

This supports changes made by the following CLs -
https://android-review.googlesource.com/#/c/359087/
https://android-review.googlesource.com/#/c/359389/

Which refactor the on-disk location as follows:
/data/lib* --> /data/asan/system/lib*
/data/vendor/* --> /data/asan/vendor/*

There are a couple of advantages to this, including better isolation
from other components, and more transparent linker renaming and
SELinux policies.

(cherry picked from commit 4113def4fa)

Bug: 36574794
Bug: 36674745
Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device
boots. All sanitized libraries are correctly located in /data/asan/*.

Change-Id: Iad8b298a66c38eb0f6327f6b51027f0728aa7a40
2017-03-31 17:24:12 -07:00
Vishwath Mohan
4113def4fa Refactor sanitized library on-disk layout - bionic.
This CL changes the linker to point to the newly refactored location
of ASAN-ified libraries on disk.

This supports changes made by the following CLs -
https://android-review.googlesource.com/#/c/359087/
https://android-review.googlesource.com/#/c/359389/

Which refactor the on-disk location as follows:
/data/lib* --> /data/asan/system/lib*
/data/vendor/* --> /data/asan/vendor/*

There are a couple of advantages to this, including better isolation
from other components, and more transparent linker renaming and
SELinux policies.

Bug: 36574794
Bug: 36674745
Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device
boots. All sanitized libraries are correctly located in /data/asan/*.

Change-Id: Iad8b298a66c38eb0f6327f6b51027f0728aa7a40
2017-03-30 20:07:50 -07:00
Dimitry Ivanov
d3e7d08845 Fix lookup logic for linked namespaces
When looking for already loaded libraries include
linked namespaces to the search, but check if
the library is accessible from the main namespace.

Bug: http://b/36008422
Bug: http://b/35417197
Bug: http://b/34052337
Bug: http://b/36660652
Bug: https://issuetracker.google.com/36636090
Test: run bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Ic7c1d48114da3ca5dc6512ef03f595dd17b6ed17
2017-03-29 15:36:40 -07:00
Dimitry Ivanov
6b0f17e588 Merge "Make anonymous namespace isoalted." 2017-03-28 00:59:09 +00:00
Dimitry Ivanov
c9dced28b6 Make anonymous namespace isoalted.
This addresses outstanding todo for anonymous namespace
and fixes an app compatibility bug.

Bug: http://b/36008422
Test: start app from http://b/36008422 and make sure it runs
Change-Id: Ie148418b944379ee1000e7274f2f6c1eca511d6c
2017-03-27 15:42:17 -07:00
Dimitry Ivanov
840ae69408 Merge "Revert "linker: add more directories to default lib paths"" 2017-03-25 07:46:22 +00:00
Treehugger Robot
deca8effd0 Merge "Load namespace configuration from ld.config.txt" 2017-03-25 05:17:32 +00:00
Dimitry Ivanov
4cabfaad34 Load namespace configuration from ld.config.txt
This change allows customization of default namespace
configuration for different executables. It also enables
target_sdk_version setup for binaries (note that this
option should explicitly be enabled in ld.config.txt).

Bug: http://b/30706810
Bug: http://b/30435785
Test: run linker-unit-tests/bionic-unit-tests, boot angler
Change-Id: Ibbe87209acf1538fc9cec04944f3d22a190c38f1
2017-03-24 15:50:45 -07:00
Dimitry Ivanov
6705e8caf5 Add systrace output for dlclose/dlsym calls
Bug: http://b/27195126
Test: manual: adb shell atrace -t 5 bionic
      and run bionic-unit-tests --gtest_filter=dl*

Change-Id: I9e93a069dd440bb643890d9952913938442ac375
2017-03-21 10:38:23 -07:00
Dimitry Ivanov
5c4a58072f Add systrace output for dlopen calls
Bug: http://b/27195126
Test: manual: adb shell atrace -t 5 bionic
      and run bionic-unit-tests --gtest_filter=dl*:Dl*

Change-Id: Ib2bad794e571b89bd1f52c9e0de642c2092e5c21
2017-03-20 13:34:52 -07:00
Dimitry Ivanov
a144697500 Revert "linker: add more directories to default lib paths"
This reverts commit 1daa18e737.

To be replaced with customized linker-namespaces for different kind of binaries.

Bug: http://b/34407260
Change-Id: Ib4e480669bbdf44ee4f59bf05f07d3e082c348c9
Test: m
2017-03-17 00:08:23 +00:00
Treehugger Robot
e5422d7d1f Merge "linker: add more directories to default lib paths" 2017-03-14 00:15:50 +00:00
Evgenii Stepanov
5b71500301 Apply ASan linker path translation to subdirectories.
Specifically, this change would translate /system/lib/hw/foo.so to /data/lib/hw/foo.so.

Bug: 30320104
Test: in SANITIZE_TARGET=address build, /proc/$PID/maps for
  system_server show libraries from /data/lib64/hw and not from
  /system/lib64/hw.
Change-Id: Ia1fa22fa1ca088fe76e41308762efe037541fc74
2017-03-13 10:04:36 -07:00
Jiyong Park
1daa18e737 linker: add more directories to default lib paths
Due to b/33681361, libraries are now installed to different paths than
before. In order for linker to load libraries from the new paths, the
default lib paths are updated.

However, this patch is temporary; different paths must be used depending
on whether the process is executing vendor executable or framework
executable. For example, vendor executable should not be able to access
/system/lib/, which is for framework-internal libs. Similarly,
framework executables should not be able to access /vendor/lib.

We have several solutions (linker namespace and DT_RUNPATH) to support
the scenario, but haven't concluded which is better. Furthermore, if we
restrict the search path right now, it will break many parts of Android
that are not yet prepared for the restriction. So, until then, we
temporarily use the single search path for both framework/vendor
executables.

Test: build & run
Change-Id: I806e9b4379bce96653b1dd3354b9f4801abb0411
2017-03-13 08:55:23 +09:00
Dimitry Ivanov
3e0821d7c2 loader: anonymous ns initialization is not required
Anonymous namesapce is zygote-specific workaround and
is not really required for other binaries.

This change allows creating namespaces without initializing
anonymous namespace.

Test: bionic-unit-tests
Change-Id: I62adc39ad69ce56b3760d36f45e3c0487c438598
2017-03-07 11:02:10 -08:00
Dimitry Ivanov
77ad64267c Remove g_default_ld_paths global variable
Test: boot, run bionic-unit-tests
Change-Id: Id05d53475cbea6d62bd5fa1ab5e457ac82bab523
2017-03-06 13:02:29 -08:00
Dimitry Ivanov
35c8e3b125 Fix greylist exception to account for linked namespaces
Do not load second copy of libraries that are supposed to
be provided by linked namespaces. Also do not print
error in the log if caller tries to open shared library
using absolute path for apps targeting N+.

Bug: http://b/35454141
Bug: http://b/26833548
Bug: http://b/35338922
Test: run bionic-unit-tests --gtest_filter=dl*
Change-Id: Icf3aeedff18d287d2ba0b3df3808b100f3ef5f7a
2017-02-27 14:16:04 -08:00
Dimitry Ivanov
2cb4dfbb8c Merge "Replace public library list with shared lib sonames (part 2/2)" 2017-02-11 19:26:49 +00:00
Dimitry Ivanov
ec90e24d33 loader: fix d-tor call order
In the case when there are multiple dependencies on
the same library in the local_group the unload may
in some situations (covered now by tests) result
calling d-tors for some libraries prematurely.

In order to have correct call order loader checks if this
is last dependency in local group before adding it to BFS
queue.

Bug: http://b/35201832
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Test: bionic-unit-tests-glibc --gtest_filter=dl*
Change-Id: I4c6955b9032acc7147a51d9f09b61d9e0818700c
2017-02-10 16:11:51 -08: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
Dimitry Ivanov
7d429d3c48 Replace public library list with shared lib sonames (part 1/2)
Replace public library list with shared lib sonames
which are property of a link between namespaces

This change does not touch any external interfaces
so from outside it behaves almost as it was before

One significant difference is that there is no longer
need to preload public libraries.

Bug: http://b/26833548
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I57e44e18a9b4f07dcd6556436346be52f52b79d7
2017-02-09 23:26:44 -08:00
Dimitry Ivanov
68e6c03081 Check overflows in c-tor instead of doing it in d-tor
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Id3b17a79732155b4e469c43c764afef1dfc59057
2017-02-01 12:55:11 -08:00
Dimitry Ivanov
3bd906146b Do not load second copy of a library into same namespace
This workaround was introduced in M in order to make sure
that linker loads libraries provided in apk in case a library
with the same name was loaded by the system.

This is no longer a problem starting with Android N because
app is using different namespace and therefore does not see
libraries loaded by the system.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I9995258c0f361e8df35420682b84e85a0cb924b4
2017-02-01 09:43:09 -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
Dimitry Ivanov
4742abdcb5 Add a way to track all dlsym calls
Add dlsym option to debug.ld.all and debug.ld.app.<appname> which
enables logging of dlsym calls.

Bug: http://b/29458203
Test: flash, set debug.ld.all to dlsym and check
      if there are messages in logcat

Change-Id: I9cb815a38b5b98aac9ebe3ac1540bcdedd2e8db0
2016-12-12 16:36:12 -08:00
Dimitry Ivanov
d9e427cf41 Bionic loader is no longer hijacking libdl.so
Do not hijack libdl.so methods but make libdl proxy calls to
loader instead. This will be replaces by calls to libc.so
once loader functionality is migrated.

Also add a lock to dl_unwind_find_exidx function call.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Bug: http://b/27106625
Change-Id: Ic33a7109a86f4262798d63a35f4c61d15b0068bb
2016-12-09 14:53:59 -08:00
Dimitry Ivanov
6c14f86309 loader: asan path translation now works for symlinks
Bionic Loader now resolves real path for a library before running
asan path-translation. This fixes situations for bundled loading
libraries which are effectively symlinks to system library;
for example:

 $ adb shell ls -l /system/app/NfcNci/lib/arm64/libnfc_nci_jni.so
 /system/app/NfcNci/lib/arm64/libnfc_nci_jni.so -> /system/lib64/libnfc_nci_jni.so

Bug: http://b/33278445
Test: make and boot
Change-Id: If14a12087c92f8ca628504556332ba0cb67c9118
2016-12-05 13:46:24 -08:00
Dimitry Ivanov
ae4a0c186f Log call to elf-constructors
Log call to constructors when dlopen logging is enabled.

Bug: http://b/29458203
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I0cd591bf147f8f910ae9def1ac4089ef44099aff
2016-11-21 12:32:08 -08:00
Treehugger Robot
585838ba32 Merge "Remove unused includes/externals" 2016-11-17 02:48:41 +00:00