Commit graph

775 commits

Author SHA1 Message Date
Dimitry Ivanov
690c8ba6e7 Merge "linker: stat /proc/self/exe instead of executable_path" into nyc-mr1-dev 2016-08-26 02:32:57 +00:00
Dimitry Ivanov
7da4bbbe87 linker: stat /proc/self/exe instead of executable_path
The absolute path to an executable may no longer be valid for
example when the file is unlinked immediately after exec.
Using /proc/self/exe instead of absolute path solves this problem.

Bug: http://b/31084669
Test: Run the app from http://b/31084669 make sure executable starts
Test: by checking ps and /proc/<pid>/exe
Change-Id: I5c819f39ef0fc4fc71b05de71e8af9ede611f04c
2016-08-25 14:58:22 -07:00
Dimitry Ivanov
a6f3b63f33 linker: warn about W+E load segments
No mapped segment from the elf file can be writable and
executable at the same time. This commit adds a warning
for malformed PT_LOAD segments in the elf-files.

Change-Id: I5e1e41bc2aabc209d3b07dd6ca2689a394294628
Test: flip protection flag for libtest_empty.so (used hexedit), adb sync
Test: run bionic-unit-tests and make sure it displays the warning.
Bug: http://b/30146890
2016-08-25 10:55:26 -07:00
Dimitry Ivanov
5aa67675f8 linker_asan: Translate absolute dlopen paths to use asan-libraries.
This patch enables absolute path translation to instrumented library
when linker_asan is in use.

Test: adb shell cat /proc/<rlid pid>/maps | grep libril-qc-qmi-1.so
      check that it is mapped from /data/vendor/lib64 and not /vendor/lib64
Bug: http://b/30320104
Change-Id: I3bc24754b192afc0a72d6f3801f7b42141ce715b
2016-08-10 18:49:56 -07:00
Dimitry Ivanov
7e2d49ae3e Check alignment along with range of mapped file fragments
Improve sanity-checks of elf-file by adding alignment check
of mapped sections and section headers.

Bug: http://b/30687964
Change-Id: I7f06ddaa56a13989ce7be847b3a73c352e32c008
2016-08-09 11:07:33 -07:00
Christopher Ferris
9a84d90c75 Make missing public soname error message clear.
If a public library is missing, make it clear that there is no
library with that soname that is missing. This can help diagnose
problems if a library exists, but the library doesn't have the right
soname.

Bug: 29400363
Change-Id: I6e782c76ef892fb18385d720b531e5177598a2b0
2016-06-17 13:46:36 -07:00
Dimitry Ivanov
bda20e78f0 Correctly handle the case of empty LD_PRELOAD entries
Previous android versions ignored empty entries for LD_PRELOAD

Bug: http://b/28936779
Change-Id: I757478fe0c604ee378186511cb13b757fd9a9864
(cherry picked from commit d799b2bb7e)
2016-05-24 16:13:56 -07:00
Dimitry Ivanov
f1d4a49598 Fix comments since we are keeping grey-list in N
Also add warning about removing access to greylisted libs
in the future Android releases.

Bug: http://b/26427993
Change-Id: I1aaa94e3bde09ab0f6594e9170d479cdb3e77d42
2016-05-23 21:52:16 -07:00
Dimitry Ivanov
3c9624a268 Do not resolve caller_ns when it is not needed
create_namespace resolves caller namespace only
when caller did not explicitly specify parent namespace.

This saves about 25 microseconds for the case when
parent_namepsace is not null (for example when creating
second classloader for the app).

Bug: http://b/28801010
Change-Id: I50ded272c931db701e5a1d8c88ed5ffb13416539
(cherry picked from commit 5240863ed5)
2016-05-23 12:43:57 -07:00
Dimitry Ivanov
a5c1c8e820 Do not check zip-entry validity on create_namespace
This operation is the most expensive one and since it is
unlikely that the zip-entry name is invalid (given that it
is constructed by the platform) - it can removed.

The worst case scenario is dlopen() of non-existing libraries
taking more time. And this use-case is not on the critical path.

Bug: http://b/28801010
Change-Id: I10a6b0bf342404ab72f0f5102ebf19f6c06ee6bf
2016-05-19 10:43:22 -07:00
Dimitry Ivanov
041cf17cdd Merge "Fix dlopen of main executable by absolute path" into nyc-dev 2016-05-18 07:33:50 +00:00
Dimitry Ivanov
49cfc899a3 linker: Allow caller to specify parent namespace
This change enables apps to share libraries opened
with RTLD_GLOBAL between different classloader namespaces.

The new parameter to create_namespace allows native_loader
to instruct the linker to share libraries belonging to
global group from a specified namespace instead of
using the caller_ns.

Bug: http://b/28560538
Bug: https://code.google.com/p/android/issues/detail?id=208458
Change-Id: I5d0c62730bbed19cdeb16c7559c74aa262a2475f
(cherry picked from commit fc2da53440)
2016-05-17 15:58:28 -07:00
Dimitry Ivanov
dcaef3710d Fix dlopen of main executable by absolute path
This CL adds initialization of inode for the main executable
which enables linker to resolve the correct soinfo when
application calls dlopen with absolute path to the
main executable.

Bug: http://b/28420266
Change-Id: I102e07bde454bd44c6e46075e3faeeb5092830d8
(cherry picked from commit 2ba1cf39ae)
2016-05-17 15:31:05 -07:00
Dimitry Ivanov
19b669b003 Remove linker-namespace functions from the header
They are intended for platform use only and we shouldn't have them
in the public header file.

Bug: http://b/28174921
Change-Id: Ib9b3d0fa9442cfa2e784a693ad567d1444d774e5
(cherry picked from commit 41fd29532b)
2016-05-11 14:19:40 -07:00
Dimitry Ivanov
bee8572ca3 Fix linker crash on trying to unload main executable
Linker crashed if linking of the main executable fails
instead of aborting with readable error message.

This patch modifies unload to soinfo_unload it all at once
in this particular case. This helps avoid situations when
one of the libraries on the DT_NEEDED list of main executable
has gotten unloaded by previous library unload because it
DT_NEEDED it too.

Example (consider following dependency tree):
main_executable
|-> liba.so
  |-> libb.so
|-> libb.so

The list of the libraries need to be unloaded in this case
is [liba.so, libb.so], but if linker does unload one by one
by the time it gets to libb.so - the soinfo for the library
is already unloaded (and the segments were unmapped).

Passing everything as an array helps soinfo_unload to check
if a library was already unloaded by looking into local_unload_list.

Bug: http://b/28565608
Change-Id: I7199290e10a186057dcf3b7b68dbce954af7dba1
(cherry picked from commit 83fcb54208)
2016-05-06 16:06:00 -07:00
Dimitry Ivanov
19b5e8cd5d Add libvorbisidec.so to the grey-list
Bug: http://b/28403395
Change-Id: Ic718b1eea4616ca87b94eee211717c4475082cab
2016-04-27 16:57:27 -07:00
Dimitry Ivanov
0551c1d47b Remove dangling links in secondary namespaces
linker didn't remove link to the soinfo from shared
namespaces on soinfo_unload, because it didn't keep
record of all namespaces the library is added to.

This change adds test for this and also fixes the
problem by introducing list of secondary namespaces
to soinfo, which is used to remove soinfo in
soinfo::remove_all_links().

Bug: http://b/28115950
Change-Id: Ifbf6e54f92fa6e88f86b6a8dd6dc22d4553afd22
(cherry picked from commit aca299ac47)
2016-04-14 12:51:55 -07:00
Dimitry Ivanov
79abce4214 linker: unload RTLD_NODELETE libraries when loading fails
Linker was not unloading libraries marked with RTLD_NODELETE
even when there was a error on load. For example when one of
dt_needed libraries was not found.

Bug: http://b/27911891
Change-Id: Ibc0bf110aa41fbfdc9f327ad8c364f2e3600af71
2016-04-13 11:46:59 -07:00
Dimitry Ivanov
8e3a3fb4f2 Add libgui.so to the grey-list
Bug: http://b/28151000
Change-Id: I7ba8f78df7dbf32de4839cc5a95ef10e8444715c
2016-04-12 14:53:06 -07:00
Dimitry Ivanov
5981d5beaf Add libexpat.so to the grey-list
Bug: http://b/28071598
Change-Id: I5545a06edfd8e0ab5b011392860ddccd6c04677f
2016-04-08 09:49:07 -07:00
Elliott Hughes
38b88a4a64 Use consistent quoting in linker messages.
Using single quotes can be more convenient -- because there's no need to
escape -- but the vast majority of existing quoting was done with double
quotes, so move in that direction.

Bug: http://b/27524191
Change-Id: I8f58593120e4c8aeaec45e16fc0178e9c162454d
2016-04-01 10:10:54 -07:00
Yabin Cui
b3ee859bbd CloseArchive() to free memory when OpenArchive fails.
Bug: 26962895
Change-Id: I42418eee320ddae857b42572690316c53f638e85
(cherry picked from commit 722072d65a)
2016-03-30 11:20:04 -07:00
Mingwei Shi
9ce09e423f libc: implement kernel vdso syscalls for i386
This patch uses __kernel_vsyscall instead of "int 0x80"
as the syscall entry point. AT_SYSINFO points to
an adapter to mask the arch specific difference and gives a
performance boost on i386 architecture.

Bug: http://b/27533895
Change-ID: Ib340c604d02c6c25714a95793737e3cfdc3fc5d7
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>

(cherry picked from commit be91052932)
2016-03-29 08:46:32 -07:00
Dimitry Ivanov
ae74e8750b linker: hide the pointer to soinfo
Handle no longer is a pointer to soinfo of
a corresponding library. This is done to
prevent access to linker internal fields.

Bug: http://b/25593965
Change-Id: I62bff0d0e5b2dc842e6bf0babb30fcc4c000be24
(cherry picked from commit d88e1f3501)
2016-03-28 15:33:07 -07:00
Dimitry Ivanov
9acb3b747c Do not add linker the _r_debug.r_map on link_image
Bug: http://b/27533895
Change-Id: Idd0fb06a5d9f400c0608ae532cc4c575211810fa
(cherry picked from commit e97d8ed70e)
2016-03-28 14:06:20 -07:00
Dimitry Ivanov
b6ac9aa6f7 Improvements to dynamic linker messages
Error messages now include executable name,
also linker doesn't abort if called on itself.

Bug: http://b/27533895
Change-Id: Ia17dd540919544b28062ed71751a1d79ee865206
(cherry picked from commit 9f0a6954c6)
2016-03-28 14:06:14 -07:00
Dimitry Ivanov
ed70f6a2a0 Move gdb support functions to a separate file
Move gdb support functions and variables to
linker_gdb_support.h/cpp

Bug: http://b/27533895
Change-Id: I96c6592a7055715b18f1137367470fe80987263f
(cherry picked from commit 6b788eeff2)
2016-03-28 14:06:09 -07:00
Dimitry Ivanov
0f478e8b44 Use insert_link_map_into_debug_map for executable
Use insert_link_map_into_debug_map to insert the main
executable's link_map to r_debug

Bug: http://b/27533895
Change-Id: I0eacb3f030ea3eb16ed50ad2011d604beece2d03
(cherry picked from commit f3064e4bc7)
2016-03-28 14:06:03 -07:00
Dimitry Ivanov
fefb4d3dcd Update a comment for init_linker_info_for_gdb
Bug: http://b/27533895
Change-Id: I8e2895ecfcc6f77a180c3735342afc93be5923d3
(cherry picked from commit 6400129628)
2016-03-28 14:05:55 -07:00
Dimitry Ivanov
05b60b24d9 Initialize linker link_map for gdb directly
Remove unnecessary construction of soinfo when
initializing linker link_map for gdb.

Bug: http://b/27533895
Change-Id: Idf32cee56309aa9c9cf260efbd17a9deae9a756b
(cherry picked from commit 8d22dd53fe)
2016-03-28 14:05:38 -07:00
Dimitry Ivanov
19930d5f6e Remove missing DT_SONAME warning from the toast
Bug: http://b/27613086
Change-Id: I9410f07dbde002d936319516313b27f9794dd597
2016-03-15 09:16:59 -07:00
Josh Gao
06abceff0f debuggerd: rethrow the full signal we receive, always.
The previous code assumed that returning would be sufficient to rethrow
signals like SIGSEGV. This is not true, for example,  in the case where a
SIGSEGV is sent via kill(2). We were previously only sending the signal
to ourselves in some cases, because using kill(2) would lose information
in the siginfo_t argument. Use rt_tgsigqueueinfo(2) instead to preserve
its contents.

Bug: http://b/27367422
Change-Id: I1be822818d5905461979c7e12dc4e9c25049273b
(cherry picked from commit 61cf3f3e03)
2016-03-10 13:58:10 -08:00
Dimitry Ivanov
31e910c407 Add libsqlite.so to the grey-list
Bug: http://b/27152660
Bug: http://b/26394120
Change-Id: I9f8f6eb8cf0d81ddf1b7769e306c08b927f3dad1
2016-03-03 18:14:14 -08:00
Dimitry Ivanov
6be6ef563e Modify android_dlwarning function to use a callback
The previous implementation of android_dlwarning was not thread-safe
and could return a pointer soon to become invalid in some situations.
This change fixed the problem. I have also removed android_dlwarning
from the dlext.h header file in case we decide to keep
android_dlwarning in the final release.

Bug: http://b/27453994
Change-Id: If6c896a80a17c4be0e18795e617712ad36a106fe
2016-03-03 21:06:41 +00:00
Dimitry Ivanov
350bdad61c linker: print "not accessible" error message to the log
Print properties of the namespace on "library is not accessible"
error to better diagnose problems with native library accessiblity

Bug: http://b/27406143
Change-Id: Icf3d6c604f09dfa015de863fdb1267d343930d2a
2016-03-01 14:49:42 -08:00
Dimitry Ivanov
df91dc2c19 Add android_dlwarning() method
This is temporary method intended to use
for a toast message on preview and beta
releases. Will be removed before the
production release.

Bug: http://b/27365747
Change-Id: I39cc716bb82863ae761b6821bcec77cce6db3781
2016-02-26 16:57:53 -08:00
Dimitry Ivanov
b8e3769067 Fix is_greylisted check in case of an absolute path
Some apps are explicitly calling System.loadLibrary(.)
for internal platform libraries like cutils.

Bug: http://b/27100558
Change-Id: I765cf3fc542778d3b487069c9955d367840b3c05
2016-02-12 13:59:24 -08:00
Christopher Ferris
5596502912 Merge "Updated to v4.4.1 kernel headers." am: 831c8a5249
am: e5df2f5f59

* commit 'e5df2f5f5911eecb64e1f32467e9d9c30aa73779':
  Updated to v4.4.1 kernel headers.
2016-02-06 05:30:12 +00:00
Christopher Ferris
05d08e9716 Updated to v4.4.1 kernel headers.
Small modifications needed to allow compilation with the new headers:

- Manually modify bionic/libc/kernel/uapi/asm-mips/asm/siginfo.h to
  remove the uapi from the include.
- PR_XXX defines are now available for mips, so remove the definition
  from linker_mips.cpp.

Bug: 23789423
Change-Id: I6dc8a03b012426d3a937db15cb24d3a50fab5a8c
2016-02-05 16:03:55 -08:00
Dimitry Ivanov
8b898d122c Merge "linker: Change the library search order" am: c92ffa95fc
am: 10e4fd56b5

* commit '10e4fd56b5e86ca1a9a6bbcb4b62f6f4592bf508':
  linker: Change the library search order
2016-02-03 22:04:35 +00:00
Dimitry Ivanov
88f5111123 linker: Change the library search order
Look into "/system/lib" before "/vendor/lib", this way
we can ensure that in case of name conflict /system libraries
take precedence.

Change-Id: Ifacdc9dc7a4e175853f499ed09782b2257f09e5a
2016-02-01 23:00:55 -08:00
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
9a020b1ff0 Merge "linker: mark library .bss pages with anon:.bss" am: 0e915b294b
am: 2c1589f568

* commit '2c1589f568ae56c85a8ae4d3d92e248d659eeee4':
  linker: mark library .bss pages with anon:.bss
2016-01-28 04:22:29 +00:00
Dimitry Ivanov
1b84afcfb1 linker: mark library .bss pages with anon:.bss
Bug: http://b/26778774
Change-Id: Ie2cdd841b7238de50ef389a897d79f915229616b
2016-01-27 18:12:03 -08:00
Dimitry Ivanov
116b57f0ec Merge "Unify names for pages allocated for small objects" am: eecae0a359
am: cdf8d292f3

* commit 'cdf8d292f3cc12516f808f1a341df1a9194adcbd':
  Unify names for pages allocated for small objects
2016-01-27 02:33:44 +00:00
Dimitry Ivanov
d9d6a84c01 Unify names for pages allocated for small objects
Bug: http://b/26776399
Change-Id: Id5b6f143a526cecca56de18ddad8857dfa1dd165
2016-01-26 17:54:13 -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
20c5c24a01 Merge "linker: align allocated blocks to 16 bytes" am: b3ec261817
am: 8aea99eacb

* commit '8aea99eacb412a94843464df84629da78422f611':
  linker: align allocated blocks to 16 bytes
2016-01-21 23:49:40 +00:00
Dimitry Ivanov
3edc5c41bb linker: align allocated blocks to 16 bytes
C/C++ requires the result of malloc/new to be
aligned for any primitive type.

Change-Id: I715b7679e738f34b3b409993fb3ef242e1321b7f
2016-01-21 14:28:33 -08:00