Commit graph

312 commits

Author SHA1 Message Date
Dimitry Ivanov
f53e7de4e9 linker: check if needed_by is nullptr
Check if needed_by is nullptr in the grey-list warning
also print the name of the library making call to dlopen()

Bug: http://b/26749878
Change-Id: I4e16223a3e3d8d1539f855a0b3f199c5529027e0
2016-02-01 12:32:22 -08:00
Dimitry Ivanov
1005748da1 Do not allow System.load() of external libraries
The greylisting mechanism had a bug that allowed
loading any library using absolute path from java code.

It mistakenly assumed they are needed by greylisted
system library when in fact it is dlopen() call from
libnativeloader.

This patch fixes this problem by checking that the library is in
fact dt_needed and it is not a dlopen call.

Bug: http://b/26394120
Bug: http://b/22548808
Change-Id: Ia3d4c19e77b04d09a6c3047d684d0c04bd5c785e
2016-01-28 17:49:49 -08:00
Dimitry Ivanov
a2a05016a0 Add libskia.so to the grey-list.
Bug: http://b/26768182
Change-Id: I3a624861f38a3b40902f44ab728d5e9e64a74f7e
2016-01-25 15:48:44 -08:00
Dimitry Ivanov
321dc06bc9 Merge "Do not unmap reserved region on dlclose" am: 3e3b992469
am: 7a55637013

* commit '7a55637013741f53f12a6ce81b80662d0a9c8a68':
  Do not unmap reserved region on dlclose
2016-01-21 05:38:03 +00:00
Dimitry Ivanov
f45b0e9ede Do not unmap reserved region on dlclose
dlclose used to unmap the part of the reserved region
for ANDROID_DLEXT_RESERVED_ADDRESS that was neccessary
to map PT_LOAD segments. With this change dlclose
replaces mapped PT_LOAD segments with a PROT_NONE,
MAP_ANONYMOUS | MAP_NORESERVE.

Previously caller was unmapping the reserved region after
the failed dlclose which led to race condition when someone
else reused the region freed by dlclose but before the unmap
by the chromium code.

Bug: http://code.google.com/p/chromium/issues/detail?id=568880
Change-Id: I0f5eaa2bf6641f83dde469b631c518482acc59a2
2016-01-20 20:57:47 -08:00
Dimitry Ivanov
78dfc4017d Greylist libui.so
Bug: http://b/26494034
Bug: http://b/26394120
Change-Id: Ie857b753061ff31aee1fafc4919cc8faed5e3f5d
2016-01-12 10:37:38 -08:00
Dimitry Ivanov
dc2bee9066 Add the name of needed_by library to the warning
Bug: http://b/26394120
Change-Id: I8dbf1d0d879e967563ad3158ee3c0e4284dfa533
2016-01-12 09:50:21 -08:00
Dimitry Ivanov
f1db47a1b3 Limit greylisting to apps targeting sdk version<=23
Bug: http://b/26394120
Change-Id: Ida7afd944cebca7170591e4181a9d5941ea2e422
2016-01-11 10:20:15 -08:00
Elliott Hughes
8849ad6287 Merge "Defend against -fstack-protector in libc startup." am: 195b85a80f
am: 6e499bc37d

* commit '6e499bc37d9caa8c914a8f83345bc2b2d8ae8132':
  Defend against -fstack-protector in libc startup.
2016-01-08 19:03:18 +00:00
Dimitry Ivanov
36ac45f783 Refine greylist to exclude transitively DT_NEEDED libraries
Bug: http://b/26394120
Change-Id: I6d63ed3ea11811c08846c19d7ca74e80e3848f3e
2016-01-07 18:43:20 -08:00
Dimitry Ivanov
a8bda26ec9 Greylist some of internal native libraries
This change is workaround for the http://b/26394120
greylisting the libraries used by some popular apps
to keep them working on dogfood builds. It will
be removed before the release.

Bug: http://b/26394120
Change-Id: I4e588b81da59f6f667aa9d2ef7e715d6607b9a36
2016-01-07 15:37:28 -08:00
Elliott Hughes
42d949ff9d Defend against -fstack-protector in libc startup.
Exactly which functions get a stack protector is up to the compiler, so
let's separate the code that sets up the environment stack protection
requires and explicitly build it with -fno-stack-protector.

Bug: http://b/26276517
Change-Id: I8719e23ead1f1e81715c32c1335da868f68369b5
2016-01-06 20:06:08 -08:00
Elliott Hughes
116b5698d4 Clarify which linker we are.
Also, we're not a debugger.

Also include LD_LIBRARY_PATH and LD_PRELOAD because they would have helped
diagnose a recent issue.

Change-Id: I7237a7236b7140ab49483c02efa705317d07bd3f
2016-01-05 11:06:50 -08:00
Dimitry Ivanov
7331fe18d7 linker: implement shared namespaces
Shared namespaces clone the list of loaded native
libraries from the caller namespace. This allows
classloaders for bundled apps to share already loaded
libraries with default namespace.

Bug: http://b/22548808
Bug: http://b/26165097
Change-Id: I8949d45937fdb38e1f586ff0679003adac0d9dad
(cherry picked from commit e78deef364)
2015-12-19 23:38:27 -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
Dimitry Ivanov
0bc3977537 Merge "Move dlsym and dladdr implementation to linker.cpp" 2015-12-11 01:26:17 +00:00
Dimitry Ivanov
4a2c5aa30c Move dlsym and dladdr implementation to linker.cpp
Bug: http://b/25716705
Bug: http://b/22865643
Change-Id: If22fc1eda219f676b5fcc06490f7901d21d1749c
2015-12-10 16:24:57 -08:00
Dimitry Ivanov
cb025e55f7 Merge "Revert "Add /odm/lib to shared lib search path"" 2015-12-10 20:17:02 +00:00
Dimitry Ivanov
39801757c3 Merge "Add permitted_when_isolated_path to linker namespaces" 2015-12-10 04:34:38 +00:00
Dimitry Ivanov
284ae3559e Add permitted_when_isolated_path to linker namespaces
The permitted_when_isolated_path is a way to white-list
directories not present in search-path. It is ignored for
not isolated namespaces.

Bug: http://b/25853516
Bug: http://b/22548808
Change-Id: Ib1538037268eea69323ea49968a34a4a1d1938a5
2015-12-09 13:54:01 -08:00
Dimitry Ivanov
5a3ab3422d Merge "Revert "Ensure that readlink has access to /proc/self/fd"" 2015-12-09 21:50:54 +00:00
Dimitry Ivanov
db43526581 Revert "Ensure that readlink has access to /proc/self/fd"
This reverts commit 4e50d0247b.

Bug: http://b/24912743
Change-Id: I5d32c670f0e16aec9c74add143158e919a301673
2015-12-09 19:36:47 +00:00
Dimitry Ivanov
40728bccbc Revert "Add /odm/lib to shared lib search path"
This reverts commit f74b041cce.

Bug: 25654402
Change-Id: I77386ea3655868d7cd1a8130afbc95e70549389e
2015-12-09 19:35:02 +00:00
Dimitry Ivanov
e371ae68ac Merge "Allow dlopening public libs using absolute path" 2015-12-05 05:25:57 +00:00
Dimitry Ivanov
22840aab47 Allow dlopening public libs using absolute path
dlopen on isolated namespaces should be able to open
public libraries using absolute path not only soname.

Bug: http://b/25853820
Change-Id: If574a67853dc51226f0f376e9e2d108316002f84
2015-12-04 21:21:35 -08:00
Elliott Hughes
939a7e0119 Track rename from base/ to android-base/.
Change-Id: I0a4592945400b1fa6892bf7c1fa8659fd711efa3
2015-12-04 15:27:46 -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
Hung-ying Tyan
0ebe2f07c3 Merge "Add /odm/lib to shared lib search path" 2015-11-19 16:38:51 +00:00
Junichi Uekawa
313632db57 Merge "Do not depend on host bits to get the right size to write." 2015-11-19 12:44:19 +00:00
Junichi Uekawa
ff35b1e659 Do not depend on host bits to get the right size to write.
x86_64 32-bit or 64-bit relocations do not depend on ELF bit size, they
are 32-bit or 64-bit respectively.

Known compiler that emits such code is nacl-clang which emits
R_X86_64_PC32 which should write 32 bits but ended up writing 64 bits.

Change-Id: Ibb6b484c0fea6a7e291362148e8ac749d6674529
2015-11-19 11:28:20 +09:00
Hung-ying Tyan
f74b041cce Add /odm/lib to shared lib search path
ODM's shared libs should live in /odm/lib on the ODM partition.

BUG: 25654402
Change-Id: I3f5c26f208af87ff2817e490e51d0b4f5b8ec98e
2015-11-18 23:45:25 +08:00
Dmitriy Ivanov
3cc35e224c Ignore target sdk version for the public namespace
This fixes the bug with using the libraries loaded
prior to android_set_target_sdk_version call.

Bug: http://b/22548808
Change-Id: I3ca2d367b0fa930a437bbb65f780834803d2ef0a
2015-11-17 18:45:12 -08:00
Dmitriy Ivanov
fbfba64068 Remove the warning about empty LD_LIBRARY_PATH
Change-Id: I3eca11512d8055ab94dd0a6badcd83ce6440d675
2015-11-16 14:23:37 -08:00
Dmitriy Ivanov
d9b08a0bc0 Fix arm64 and x86 builds
Change-Id: Ic3746b2f200f42218b6ac857c1631e873c767c17
2015-11-16 13:17:27 -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
fd7a91e692 linker: cleanup solist after unsuccessful read
Bug: http://b/25560017
Change-Id: I03c5a1d7aed34c480d341aacfb3b1afdfa037b99
2015-11-06 10:44:37 -08:00
Dmitriy Ivanov
126af757c6 Implement load at fixed address feature
Bug: http://b/24683631
Change-Id: I3a39ab526c8f9e213339b60e135e5459d0f41381
2015-10-27 11:27:34 -07:00
Dmitriy Ivanov
4f7a7ad3fe Implement Library Load Order Randomization
Bug: http://b/24047022
Change-Id: I36e05b403bfbaae8542a95147f9114a8b9c8ac0e
2015-10-22 18:26:07 -07:00
Dimitry Ivanov
5fd94dfe3b Merge "Replace auto -> const auto&/auto&&" 2015-10-16 20:37:34 +00:00
Dimitry Ivanov
9c2122e803 Merge "Fix R_AARCH64_ABS/PREL relocations" 2015-10-16 20:36:25 +00:00
Dmitriy Ivanov
77f91c6d99 Fix R_AARCH64_ABS/PREL relocations
According to specification arm64 relocations
should not use *reloc value.

See http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf
section 4.6.5

Bug: http://b/24977219
Bug: http://b/24527155
Change-Id: I3813255771f408ba957963c6ad56ed08e5110d83
2015-10-16 10:42:16 -07:00
Dmitriy Ivanov
4e50d0247b Ensure that readlink has access to /proc/self/fd
/proc/self/fd is not available when PR_DUMPABLE is set to 0
which is default for the user builds. It leads to permission
denials on readlink.

This change fixes the problem by setting PR_DUMPABLE flag to 1
for readlink and restoring it's previous value after the call.

Bug: http://b/24912743
Change-Id: I3fd179c5c6b56af96d6a15ee597024ccb15e1a13
(cherry picked from commit cf92738fa5)
2015-10-14 18:24:54 -07:00
Dmitriy Ivanov
fae39d2bf9 Log dlopen failures caused by text relocations
Some apps will fail to load native libraries with
text relocations when switching target sdk version to M.
It could be hard to diagnose because some of them
suppress dlerror and/or UnsatisfiedLinkError.

This change unconditionally logs the error message making
the cause of the failure more visible to developers.

Bug: http://b/24876001
Change-Id: I0477a0d1307d0879000f3a3a43b974b4cf34bdb2
(cherry picked from commit f32b689d3d)
2015-10-13 15:48:57 -07:00
Dmitriy Ivanov
5dce8948b6 Replace auto -> const auto&/auto&&
Change-Id: Ie484e5a296b5dd222a9545d8539d40d97a6c158c
2015-10-13 12:14:16 -07:00
Lazar Trsic
6f2d3104c8 Correctly resolve realpath for absolute paths
Introduced by: https://android-review.googlesource.com/174475

Change-Id: I44e00040b28be167d5141454f919340afec6084e
2015-10-13 10:57:41 -07:00
Josh Gao
93c0f5ee00 Move VDSO pointers to a shared globals struct.
Change-Id: I01cbc9cf0917dc1fac52d9205bda2c68529d12ef
2015-10-09 15:59:04 -07:00
Dmitriy Ivanov
8068786ae6 Remove textrels support for platform libs
Bug: http://b/20013628
Change-Id: Ia9382c7113e09bb6aed65072543e4ebe33026cf8
2015-10-09 13:59:42 -07:00
Dmitriy Ivanov
a1feb117e4 Make dt_runpath work for libraries opened from apk
This patch also fixes realpath for libraries opened directly
from apks.

Bug: http://b/21960914
Bug: http://b/21961857
Change-Id: I35ade661c87f1d448191f385811f6e9fd3cacf11
2015-10-07 11:44:53 -07:00
Dmitriy Ivanov
7e039937b8 Fix the comment
Change-Id: Ic8126cf92d12851cccaa3e2e781f075c9f6c283a
2015-10-01 14:02:19 -07:00
Dmitriy Ivanov
b48275045d Optimize dlopen from a zip file
This change makes dynamic linker reuse ZipArchiveHandles in
ld_library_path on dlopen to optimize the lookup of dt_needed
libraries.

Bug: http://b/21960534
Change-Id: I65f897910d46dd2ffabdcb0b7842db2f127eee30
2015-09-30 10:47:11 -07:00