From a352c6957132a9ee211f9fa498388b48797b2a8e Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Tue, 5 Jan 2016 11:18:42 -0800 Subject: Temporary move __udivdi3 back to LIBC for x86 Bug: http://b/26289334 Bug: http://b/26413821 Change-Id: Ifb0eb6f16aca54cb4a9184a6394992ee57dd3408 --- libc/libc.arm.brillo.map | 2 +- libc/libc.arm.map | 2 +- libc/libc.map.txt | 3 ++- libc/libc.mips.brillo.map | 2 +- libc/libc.mips.map | 2 +- libc/libc.x86.brillo.map | 2 +- libc/libc.x86.map | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libc/libc.arm.brillo.map b/libc/libc.arm.brillo.map index 317b3b2d3..ea2fe9eb6 100644 --- a/libc/libc.arm.brillo.map +++ b/libc/libc.arm.brillo.map @@ -1402,7 +1402,7 @@ LIBC_PRIVATE { __swrite; # arm x86 mips __swsetup; # arm x86 mips __truncdfsf2; # arm - __udivdi3; # arm x86 mips + __udivdi3; # arm mips __udivsi3; # arm __unorddf2; # arm __unordsf2; # arm diff --git a/libc/libc.arm.map b/libc/libc.arm.map index efd1106f6..95227591d 100644 --- a/libc/libc.arm.map +++ b/libc/libc.arm.map @@ -1414,7 +1414,7 @@ LIBC_PRIVATE { __swrite; # arm x86 mips __swsetup; # arm x86 mips __truncdfsf2; # arm - __udivdi3; # arm x86 mips + __udivdi3; # arm mips __udivsi3; # arm __unorddf2; # arm __unordsf2; # arm diff --git a/libc/libc.map.txt b/libc/libc.map.txt index d2e2b1ba4..4d06c52c3 100644 --- a/libc/libc.map.txt +++ b/libc/libc.map.txt @@ -223,6 +223,7 @@ LIBC { __timer_getoverrun; # arm x86 mips __timer_gettime; # arm x86 mips __timer_settime; # arm x86 mips + __udivdi3; # x86 __umask_chk; __vsnprintf_chk; __vsprintf_chk; @@ -1455,7 +1456,7 @@ LIBC_PRIVATE { __system_property_update; # arm64 x86_64 mips64 __system_property_wait_any; # arm64 x86_64 mips64 __truncdfsf2; # arm - __udivdi3; # arm x86 mips + __udivdi3; # arm mips __udivsi3; # arm __umoddi3; # x86 mips __unorddf2; # arm diff --git a/libc/libc.mips.brillo.map b/libc/libc.mips.brillo.map index f268509ed..9a20726d3 100644 --- a/libc/libc.mips.brillo.map +++ b/libc/libc.mips.brillo.map @@ -1264,7 +1264,7 @@ LIBC_PRIVATE { __swbuf; # arm x86 mips __swrite; # arm x86 mips __swsetup; # arm x86 mips - __udivdi3; # arm x86 mips + __udivdi3; # arm mips __umoddi3; # x86 mips _fwalk; # arm x86 mips free_malloc_leak_info; diff --git a/libc/libc.mips.map b/libc/libc.mips.map index a72d680a7..5981b465b 100644 --- a/libc/libc.mips.map +++ b/libc/libc.mips.map @@ -1276,7 +1276,7 @@ LIBC_PRIVATE { __swbuf; # arm x86 mips __swrite; # arm x86 mips __swsetup; # arm x86 mips - __udivdi3; # arm x86 mips + __udivdi3; # arm mips __umoddi3; # x86 mips __wait4; # arm x86 mips nobrillo _fwalk; # arm x86 mips diff --git a/libc/libc.x86.brillo.map b/libc/libc.x86.brillo.map index 333b4193c..f4de17808 100644 --- a/libc/libc.x86.brillo.map +++ b/libc/libc.x86.brillo.map @@ -205,6 +205,7 @@ LIBC { __timer_getoverrun; # arm x86 mips __timer_gettime; # arm x86 mips __timer_settime; # arm x86 mips + __udivdi3; # x86 __umask_chk; __vsnprintf_chk; __vsprintf_chk; @@ -1263,7 +1264,6 @@ LIBC_PRIVATE { __swbuf; # arm x86 mips __swrite; # arm x86 mips __swsetup; # arm x86 mips - __udivdi3; # arm x86 mips __umoddi3; # x86 mips _fwalk; # arm x86 mips free_malloc_leak_info; diff --git a/libc/libc.x86.map b/libc/libc.x86.map index 06640f009..064ae198c 100644 --- a/libc/libc.x86.map +++ b/libc/libc.x86.map @@ -206,6 +206,7 @@ LIBC { __timer_getoverrun; # arm x86 mips __timer_gettime; # arm x86 mips __timer_settime; # arm x86 mips + __udivdi3; # x86 __umask_chk; __vsnprintf_chk; __vsprintf_chk; @@ -1275,7 +1276,6 @@ LIBC_PRIVATE { __swbuf; # arm x86 mips __swrite; # arm x86 mips __swsetup; # arm x86 mips - __udivdi3; # arm x86 mips __umoddi3; # x86 mips __wait4; # arm x86 mips nobrillo _fwalk; # arm x86 mips -- cgit v1.2.3 From 6b5cbea099e6663facc86b898b64291456442059 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 6 Jan 2016 11:12:06 -0800 Subject: Temporary hack to avoid stack protector crashes. It'll take me a while to refactor things cleanly, but if we just want something that boots for testing... Bug: http://b/26276517 Change-Id: I24729d3dc546e36e0eff383f0d1d05c3aa1f2e0b --- libc/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/Android.mk b/libc/Android.mk index 83e1fb505..d5a57c342 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -616,6 +616,7 @@ libc_openbsd_src_files_32 += \ libc_common_cflags := \ -D_LIBC=1 \ -Wall -Wextra -Wunused \ + -fno-stack-protector \ use_clang := $(USE_CLANG_PLATFORM_BUILD) -- cgit v1.2.3 From 917af43e980c5d1cbaa31a06c4501939290b98b6 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 6 Jan 2016 18:52:52 +0000 Subject: Revert "system_properties.cpp: special case ro.* properties" This reverts commit c5fd81ab2524a06be907d9c5234e79346bbbbd7c. Bug: 26416032 Change-Id: Id2d6761fdf55efa28c0b08b597daaa5cd381d758 --- libc/bionic/system_properties.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp index 28cce4050..27204553d 100644 --- a/libc/bionic/system_properties.cpp +++ b/libc/bionic/system_properties.cpp @@ -826,10 +826,6 @@ static bool map_system_property_area(bool access_rw, bool* fsetxattr_failed) { } static prop_area* get_prop_area_for_name(const char* name) { - if (strncmp(name, "ro.", 3) == 0) { - name += 3; - } - auto entry = list_find(prefixes, [name](prefix_node* l) { return l->prefix[0] == '*' || !strncmp(l->prefix, name, l->prefix_len); }); -- cgit v1.2.3 From d6ee917a85245259a8fe8cdfecd4b8e48029b7d0 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Thu, 7 Jan 2016 11:16:43 -0800 Subject: 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 --- linker/linker.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index 130e34145..e09f74f44 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -153,6 +153,62 @@ static const char* const kAsanDefaultLdPaths[] = { nullptr }; +// TODO(dimitry): This is workaround for http://b/26394120 - it will be removed before the release +static bool is_greylisted(const char* name) { + static const char* const kLibraryGreyList[] = { + "libLLVM.so", + "libRScpp.so", + "libaudioutils.so", + "libbacktrace.so", + "libbase.so", + "libbinder.so", + "libc++.so", + "libcamera_client.so", + "libcamera_metadata.so", + "libcommon_time_client.so", + "libcrypto.so", + "libcutils.so", + "libdrmframework.so", + "libexpat.so", + "libgui.so", + "libhardware.so", + "libicui18n.so", + "libicuuc.so", + "libmediautils.so", + "libmedia.so", + "libnativehelper.so", + "libnbaio.so", + "libnetd_client.so", + "libopus.so", + "libpowermanager.so", + "libsonivox.so", + "libspeexresampler.so", + "libpowermanager.so", + "libssl.so", + "libstagefright_avc_common.so", + "libstagefright_enc_common.so", + "libstagefright_foundation.so", + "libstagefright_omx.so", + "libstagefright_yuv.so", + "libstagefright.so", + "libsync.so", + "libui.so", + "libunwind.so", + "libutils.so", + "libvorbisidec.so", + nullptr + }; + + for (size_t i = 0; kLibraryGreyList[i] != nullptr; ++i) { + if (strcmp(name, kLibraryGreyList[i]) == 0) { + return true; + } + } + + return false; +} +// END OF WORKAROUND + static const ElfW(Versym) kVersymNotNeeded = 0; static const ElfW(Versym) kVersymGlobal = 1; @@ -1608,6 +1664,14 @@ static int open_library(android_namespace_t* ns, fd = open_library_on_paths(zip_archive_cache, name, file_offset, ns->get_default_library_paths(), realpath); } + // TODO(dimitry): workaround for http://b/26394120 - will be removed before the release + if (fd == -1 && ns != &g_default_namespace && is_greylisted(name)) { + // try searching for it on default_namespace default_library_path + fd = open_library_on_paths(zip_archive_cache, name, file_offset, + g_default_namespace.get_default_library_paths(), realpath); + } + // END OF WORKAROUND + return fd; } @@ -1708,10 +1772,16 @@ static bool load_library(android_namespace_t* ns, } if (!ns->is_accessible(realpath)) { - // do not load libraries if they are not accessible for the specified namespace. - DL_ERR("library \"%s\" is not accessible for the namespace \"%s\"", - name, ns->get_name()); - return false; + // TODO(dimitry): workaround for http://b/26394120 - will be removed before the release + if (is_greylisted(name)) { + DL_WARN("library \"%s\" (\"%s\") is not accessible for the namespace \"%s\" - the access is temporarily granted as a workaround for http://b/26394120", + name, realpath.c_str(), ns->get_name()); + } else { + // do not load libraries if they are not accessible for the specified namespace. + DL_ERR("library \"%s\" is not accessible for the namespace \"%s\"", + name, ns->get_name()); + return false; + } } soinfo* si = soinfo_alloc(ns, realpath.c_str(), &file_stat, file_offset, rtld_flags); -- cgit v1.2.3 From 7d27af70fafc6208082b99144e1e690cae243fe8 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Thu, 7 Jan 2016 18:43:20 -0800 Subject: Refine greylist to exclude transitively DT_NEEDED libraries Bug: http://b/26394120 Change-Id: I6d63ed3ea11811c08846c19d7ca74e80e3848f3e --- linker/linker.cpp | 63 +++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index e09f74f44..94cb79a00 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -153,52 +153,37 @@ static const char* const kAsanDefaultLdPaths[] = { nullptr }; +static bool is_system_library(const std::string& realpath) { + for (const auto& dir : g_default_namespace.get_default_library_paths()) { + if (file_is_in_dir(realpath, dir)) { + return true; + } + } + return false; +} + // TODO(dimitry): This is workaround for http://b/26394120 - it will be removed before the release -static bool is_greylisted(const char* name) { +static bool is_greylisted(const char* name, const soinfo* needed_by) { static const char* const kLibraryGreyList[] = { - "libLLVM.so", - "libRScpp.so", - "libaudioutils.so", - "libbacktrace.so", - "libbase.so", + "libandroid_runtime.so", "libbinder.so", - "libc++.so", - "libcamera_client.so", - "libcamera_metadata.so", - "libcommon_time_client.so", "libcrypto.so", "libcutils.so", - "libdrmframework.so", - "libexpat.so", - "libgui.so", - "libhardware.so", - "libicui18n.so", - "libicuuc.so", - "libmediautils.so", "libmedia.so", "libnativehelper.so", - "libnbaio.so", - "libnetd_client.so", - "libopus.so", - "libpowermanager.so", - "libsonivox.so", - "libspeexresampler.so", - "libpowermanager.so", "libssl.so", - "libstagefright_avc_common.so", - "libstagefright_enc_common.so", - "libstagefright_foundation.so", - "libstagefright_omx.so", - "libstagefright_yuv.so", "libstagefright.so", - "libsync.so", - "libui.so", - "libunwind.so", "libutils.so", - "libvorbisidec.so", nullptr }; + // if the library needed by a system library - implicitly assume it + // is greylisted + + if (needed_by != nullptr && is_system_library(needed_by->get_realpath())) { + return true; + } + for (size_t i = 0; kLibraryGreyList[i] != nullptr; ++i) { if (strcmp(name, kLibraryGreyList[i]) == 0) { return true; @@ -1665,7 +1650,7 @@ static int open_library(android_namespace_t* ns, } // TODO(dimitry): workaround for http://b/26394120 - will be removed before the release - if (fd == -1 && ns != &g_default_namespace && is_greylisted(name)) { + if (fd == -1 && ns != &g_default_namespace && is_greylisted(name, needed_by)) { // try searching for it on default_namespace default_library_path fd = open_library_on_paths(zip_archive_cache, name, file_offset, g_default_namespace.get_default_library_paths(), realpath); @@ -1773,9 +1758,13 @@ static bool load_library(android_namespace_t* ns, if (!ns->is_accessible(realpath)) { // TODO(dimitry): workaround for http://b/26394120 - will be removed before the release - if (is_greylisted(name)) { - DL_WARN("library \"%s\" (\"%s\") is not accessible for the namespace \"%s\" - the access is temporarily granted as a workaround for http://b/26394120", - name, realpath.c_str(), ns->get_name()); + const soinfo* needed_by = task->get_needed_by(); + if (is_greylisted(name, needed_by)) { + // print warning only if needed by non-system library + if (needed_by == nullptr || !is_system_library(needed_by->get_realpath())) { + DL_WARN("library \"%s\" (\"%s\") is not accessible for the namespace \"%s\" - the access is temporarily granted as a workaround for http://b/26394120", + name, realpath.c_str(), ns->get_name()); + } } else { // do not load libraries if they are not accessible for the specified namespace. DL_ERR("library \"%s\" is not accessible for the namespace \"%s\"", -- cgit v1.2.3 From 96df61eb08f4ca95d6ba0a868bca1756982fb0f2 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Tue, 12 Jan 2016 09:48:09 -0800 Subject: Explicit binary op order for both gcc and clang/llvm. * gcc assembler parses (1 << n - 1) as ((1 << n) - 1) * llvm assembler parses (1 << n - 1) as (1 << (n - 1)) BUG: 26289334 Change-Id: Iaaa3d07f59c0f87cb1b80b9a1c4e765b66846791 --- libc/arch-x86/atom/string/sse2-strrchr-atom.S | 60 +++++++++++++-------------- libc/arch-x86/atom/string/sse2-wcsrchr-atom.S | 8 ++-- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libc/arch-x86/atom/string/sse2-strrchr-atom.S b/libc/arch-x86/atom/string/sse2-strrchr-atom.S index da3dc3bcb..e916bc1e5 100644 --- a/libc/arch-x86/atom/string/sse2-strrchr-atom.S +++ b/libc/arch-x86/atom/string/sse2-strrchr-atom.S @@ -278,7 +278,7 @@ L(find_zero): jnz L(FindZeroExit2) test $0x04, %cl jnz L(FindZeroExit3) - and $1 << 4 - 1, %eax + and $(1 << 4) - 1, %eax jz L(return_value) POP (%ebx) @@ -296,7 +296,7 @@ L(find_zero_8): jnz L(FindZeroExit6) test $0x40, %cl jnz L(FindZeroExit7) - and $1 << 8 - 1, %eax + and $(1 << 8) - 1, %eax jz L(return_value) POP (%ebx) @@ -317,7 +317,7 @@ L(find_zero_high): jnz L(FindZeroExit10) test $0x04, %ch jnz L(FindZeroExit11) - and $1 << 12 - 1, %eax + and $(1 << 12) - 1, %eax jz L(return_value) POP (%ebx) @@ -335,7 +335,7 @@ L(find_zero_high_8): jnz L(FindZeroExit14) test $0x40, %ch jnz L(FindZeroExit15) - and $1 << 16 - 1, %eax + and $(1 << 16) - 1, %eax jz L(return_value) POP (%ebx) @@ -359,7 +359,7 @@ L(FindZeroExit1): .p2align 4 L(FindZeroExit2): - and $1 << 2 - 1, %eax + and $(1 << 2) - 1, %eax jz L(return_value) POP (%ebx) @@ -371,7 +371,7 @@ L(FindZeroExit2): .p2align 4 L(FindZeroExit3): - and $1 << 3 - 1, %eax + and $(1 << 3) - 1, %eax jz L(return_value) POP (%ebx) @@ -383,7 +383,7 @@ L(FindZeroExit3): .p2align 4 L(FindZeroExit5): - and $1 << 5 - 1, %eax + and $(1 << 5) - 1, %eax jz L(return_value) POP (%ebx) @@ -395,7 +395,7 @@ L(FindZeroExit5): .p2align 4 L(FindZeroExit6): - and $1 << 6 - 1, %eax + and $(1 << 6) - 1, %eax jz L(return_value) POP (%ebx) @@ -407,7 +407,7 @@ L(FindZeroExit6): .p2align 4 L(FindZeroExit7): - and $1 << 7 - 1, %eax + and $(1 << 7) - 1, %eax jz L(return_value) POP (%ebx) @@ -419,7 +419,7 @@ L(FindZeroExit7): .p2align 4 L(FindZeroExit9): - and $1 << 9 - 1, %eax + and $(1 << 9) - 1, %eax jz L(return_value) POP (%ebx) @@ -431,7 +431,7 @@ L(FindZeroExit9): .p2align 4 L(FindZeroExit10): - and $1 << 10 - 1, %eax + and $(1 << 10) - 1, %eax jz L(return_value) POP (%ebx) @@ -443,7 +443,7 @@ L(FindZeroExit10): .p2align 4 L(FindZeroExit11): - and $1 << 11 - 1, %eax + and $(1 << 11) - 1, %eax jz L(return_value) POP (%ebx) @@ -455,7 +455,7 @@ L(FindZeroExit11): .p2align 4 L(FindZeroExit13): - and $1 << 13 - 1, %eax + and $(1 << 13) - 1, %eax jz L(return_value) POP (%ebx) @@ -467,7 +467,7 @@ L(FindZeroExit13): .p2align 4 L(FindZeroExit14): - and $1 << 14 - 1, %eax + and $(1 << 14) - 1, %eax jz L(return_value) POP (%ebx) @@ -479,7 +479,7 @@ L(FindZeroExit14): .p2align 4 L(FindZeroExit15): - and $1 << 15 - 1, %eax + and $(1 << 15) - 1, %eax jz L(return_value) POP (%ebx) @@ -619,7 +619,7 @@ L(prolog_find_zero_1): jnz L(PrologFindZeroExit2) test $0x04, %cl jnz L(PrologFindZeroExit3) - and $1 << 4 - 1, %eax + and $(1 << 4) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN @@ -632,7 +632,7 @@ L(prolog_find_zero_8): jnz L(PrologFindZeroExit6) test $0x40, %cl jnz L(PrologFindZeroExit7) - and $1 << 8 - 1, %eax + and $(1 << 8) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN @@ -648,7 +648,7 @@ L(prolog_find_zero_high): jnz L(PrologFindZeroExit10) test $0x04, %ch jnz L(PrologFindZeroExit11) - and $1 << 12 - 1, %eax + and $(1 << 12) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN @@ -661,7 +661,7 @@ L(prolog_find_zero_high_8): jnz L(PrologFindZeroExit14) test $0x40, %ch jnz L(PrologFindZeroExit15) - and $1 << 16 - 1, %eax + and $(1 << 16) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN @@ -675,77 +675,77 @@ L(PrologFindZeroExit1): .p2align 4 L(PrologFindZeroExit2): - and $1 << 2 - 1, %eax + and $(1 << 2) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit3): - and $1 << 3 - 1, %eax + and $(1 << 3) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit5): - and $1 << 5 - 1, %eax + and $(1 << 5) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit6): - and $1 << 6 - 1, %eax + and $(1 << 6) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit7): - and $1 << 7 - 1, %eax + and $(1 << 7) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit9): - and $1 << 9 - 1, %eax + and $(1 << 9) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit10): - and $1 << 10 - 1, %eax + and $(1 << 10) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit11): - and $1 << 11 - 1, %eax + and $(1 << 11) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit13): - and $1 << 13 - 1, %eax + and $(1 << 13) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit14): - and $1 << 14 - 1, %eax + and $(1 << 14) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN .p2align 4 L(PrologFindZeroExit15): - and $1 << 15 - 1, %eax + and $(1 << 15) - 1, %eax jnz L(match_case1) xor %eax, %eax RETURN diff --git a/libc/arch-x86/atom/string/sse2-wcsrchr-atom.S b/libc/arch-x86/atom/string/sse2-wcsrchr-atom.S index e30779d4c..1a55df24a 100644 --- a/libc/arch-x86/atom/string/sse2-wcsrchr-atom.S +++ b/libc/arch-x86/atom/string/sse2-wcsrchr-atom.S @@ -280,7 +280,7 @@ L(find_zero): .p2align 4 L(find_zero_in_second_wchar): - and $1 << 5 - 1, %eax + and $(1 << 5) - 1, %eax jz L(return_value) POP (%esi) @@ -296,7 +296,7 @@ L(find_zero_in_second_wchar): L(find_zero_in_third_or_fourth_wchar): test $15, %ch jz L(find_zero_in_fourth_wchar) - and $1 << 9 - 1, %eax + and $(1 << 9) - 1, %eax jz L(return_value) POP (%esi) @@ -368,7 +368,7 @@ L(prolog_find_zero_1): .p2align 4 L(prolog_find_zero_in_second_wchar): - and $1 << 5 - 1, %eax + and $(1 << 5) - 1, %eax jz L(return_null) test $15 << 4, %al @@ -380,7 +380,7 @@ L(prolog_find_zero_in_second_wchar): L(prolog_find_zero_in_third_or_fourth_wchar): test $15, %ch jz L(prolog_find_zero_in_fourth_wchar) - and $1 << 9 - 1, %eax + and $(1 << 9) - 1, %eax jz L(return_null) test %ah, %ah -- cgit v1.2.3 From 895d8f6e5b8c760b2325a6d414569c5da4bdeeb5 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Tue, 12 Jan 2016 10:37:38 -0800 Subject: Greylist libui.so Bug: http://b/26494034 Bug: http://b/26394120 Change-Id: Ie857b753061ff31aee1fafc4919cc8faed5e3f5d --- linker/linker.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/linker/linker.cpp b/linker/linker.cpp index 791f94d41..dbe414821 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -173,6 +173,7 @@ static bool is_greylisted(const char* name, const soinfo* needed_by) { "libnativehelper.so", "libssl.so", "libstagefright.so", + "libui.so", "libutils.so", nullptr }; -- cgit v1.2.3 From e84834614eb2f32e60cb1ec12a7c4a42de5d0d3a Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Mon, 7 Mar 2016 17:13:34 +0000 Subject: Revert "libm: rename LIBC_PRIVATE to LIBC_DEPRECATED" Vendor blobs strike back. This reverts commit 9721bb3f0b7c8c45f42d2874c908a177615f42b5. Bug: http://b/27518190 Change-Id: I3fbe71123840edc51a1a804f6c8e83c84958192d --- libm/libm.arm.map | 2 +- libm/libm.map.txt | 2 +- libm/libm.mips.map | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libm/libm.arm.map b/libm/libm.arm.map index 842f46c42..e781f2d74 100644 --- a/libm/libm.arm.map +++ b/libm/libm.arm.map @@ -272,7 +272,7 @@ LIBC { *; }; -LIBC_DEPRECATED { # arm mips +LIBC_PRIVATE { # arm mips global: # arm mips ___Unwind_Backtrace; # arm ___Unwind_ForcedUnwind; # arm diff --git a/libm/libm.map.txt b/libm/libm.map.txt index d27360370..075ebd580 100644 --- a/libm/libm.map.txt +++ b/libm/libm.map.txt @@ -271,7 +271,7 @@ LIBC { *; }; -LIBC_DEPRECATED { # arm mips +LIBC_PRIVATE { # arm mips global: # arm mips ___Unwind_Backtrace; # arm ___Unwind_ForcedUnwind; # arm diff --git a/libm/libm.mips.map b/libm/libm.mips.map index 2429dba55..476c6ad06 100644 --- a/libm/libm.mips.map +++ b/libm/libm.mips.map @@ -272,7 +272,7 @@ LIBC { *; }; -LIBC_DEPRECATED { # arm mips +LIBC_PRIVATE { # arm mips global: # arm mips __fixdfdi; # arm mips __fixsfdi; # arm mips -- cgit v1.2.3 From d1981c0f6f80c6218730b6bd9f8f8f17b4a9c868 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 4 Mar 2016 11:53:09 -0800 Subject: Improve and fix the stack-protector tests. Bug: http://b/26888853 (cherry picked from commit fc69a8ad5f0d9b63de48e3858fb4811ede7ac64e) Change-Id: Ibc431076000b9a8db46f68f858480045b03b6e79 --- libc/bionic/__libc_init_main_thread.cpp | 4 ++ libc/bionic/libc_init_common.cpp | 10 ++- libc/private/bionic_globals.h | 10 +-- libc/private/bionic_tls.h | 4 +- tests/Android.mk | 1 + tests/stack_protector_test.cpp | 109 ++++++++++++-------------------- tests/stack_protector_test_helper.cpp | 24 +++++++ 7 files changed, 86 insertions(+), 76 deletions(-) create mode 100644 tests/stack_protector_test_helper.cpp diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp index e1445cbdb..a29d8a725 100644 --- a/libc/bionic/__libc_init_main_thread.cpp +++ b/libc/bionic/__libc_init_main_thread.cpp @@ -74,6 +74,10 @@ void __libc_init_main_thread(KernelArgumentBlock& args) { main_thread.attr.stack_size = 0; // User code should never see this; we'll compute it when asked. // TODO: the main thread's sched_policy and sched_priority need to be queried. + // The TLS stack guard is set from the global, so ensure that we've initialized the global + // before we initialize the TLS. + __libc_init_global_stack_chk_guard(args); + __init_thread(&main_thread); __init_tls(&main_thread); diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp index ebd15957f..c2a5feda0 100644 --- a/libc/bionic/libc_init_common.cpp +++ b/libc/bionic/libc_init_common.cpp @@ -64,10 +64,17 @@ char** environ; // Declared in "private/bionic_ssp.h". uintptr_t __stack_chk_guard = 0; +void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args) { + // AT_RANDOM is a pointer to 16 bytes of randomness on the stack. + // Take the first 4/8 for the -fstack-protector implementation. + __stack_chk_guard = *reinterpret_cast(args.getauxval(AT_RANDOM)); +} + void __libc_init_globals(KernelArgumentBlock& args) { // Initialize libc globals that are needed in both the linker and in libc. // In dynamic binaries, this is run at least twice for different copies of the // globals, once for the linker's copy and once for the one in libc.so. + __libc_init_global_stack_chk_guard(args); __libc_auxv = args.auxv; __libc_globals.initialize(); __libc_globals.mutate([&args](libc_globals* globals) { @@ -83,9 +90,6 @@ void __libc_init_common(KernelArgumentBlock& args) { __progname = args.argv[0] ? args.argv[0] : ""; __abort_message_ptr = args.abort_message_ptr; - // AT_RANDOM is a pointer to 16 bytes of randomness on the stack. - __stack_chk_guard = *reinterpret_cast(getauxval(AT_RANDOM)); - // Get the main thread from TLS and add it to the thread list. pthread_internal_t* main_thread = __get_thread(); __pthread_internal_add(main_thread); diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h index c802e3a4d..bcb05a0dc 100644 --- a/libc/private/bionic_globals.h +++ b/libc/private/bionic_globals.h @@ -25,10 +25,12 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #ifndef _PRIVATE_BIONIC_GLOBALS_H #define _PRIVATE_BIONIC_GLOBALS_H #include + #include "private/bionic_malloc_dispatch.h" #include "private/bionic_vdso.h" #include "private/WriteProtected.h" @@ -42,9 +44,9 @@ struct libc_globals { __LIBC_HIDDEN__ extern WriteProtected __libc_globals; class KernelArgumentBlock; -__LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals, - KernelArgumentBlock& args); -__LIBC_HIDDEN__ void __libc_init_setjmp_cookie(libc_globals* globals, - KernelArgumentBlock& args); +__LIBC_HIDDEN__ void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args); __LIBC_HIDDEN__ void __libc_init_malloc(libc_globals* globals); +__LIBC_HIDDEN__ void __libc_init_setjmp_cookie(libc_globals* globals, KernelArgumentBlock& args); +__LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args); + #endif diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h index f13615dfc..c61e2ffdd 100644 --- a/libc/private/bionic_tls.h +++ b/libc/private/bionic_tls.h @@ -30,7 +30,7 @@ #define __BIONIC_PRIVATE_BIONIC_TLS_H_ #include -#include + #include "bionic_macros.h" #include "__get_tls.h" @@ -117,7 +117,7 @@ __END_DECLS #if defined(__cplusplus) class KernelArgumentBlock; -extern __LIBC_HIDDEN__ void __libc_init_main_thread(KernelArgumentBlock&); +extern void __libc_init_main_thread(KernelArgumentBlock&); #endif #endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */ diff --git a/tests/Android.mk b/tests/Android.mk index 0db63d952..956b76fcc 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -78,6 +78,7 @@ libBionicStandardTests_src_files := \ setjmp_test.cpp \ signal_test.cpp \ stack_protector_test.cpp \ + stack_protector_test_helper.cpp \ stack_unwinding_test.cpp \ stdatomic_test.cpp \ stdint_test.cpp \ diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp index 22285d123..5f5a24174 100644 --- a/tests/stack_protector_test.cpp +++ b/tests/stack_protector_test.cpp @@ -27,108 +27,83 @@ #include #include -extern "C" pid_t gettid(); - -// For x86, bionic and glibc have per-thread stack guard values (all identical). -#if defined(__i386__) -static uint32_t GetGuardFromTls() { - uint32_t guard; - asm ("mov %%gs:0x14, %0": "=d" (guard)); - return guard; -} +#include "private/bionic_tls.h" + +extern "C" pid_t gettid(); // glibc defines this but doesn't declare it anywhere. + +#if defined(__BIONIC__) +extern uintptr_t __stack_chk_guard; +#endif struct stack_protector_checker { std::set tids; - std::set guards; + std::set guards; void Check() { pid_t tid = gettid(); - uint32_t guard = GetGuardFromTls(); + void* guard = __get_tls()[TLS_SLOT_STACK_GUARD]; - printf("[thread %d] %%gs:0x14 = 0x%08x\n", tid, guard); + printf("[thread %d] TLS stack guard = %p\n", tid, guard); // Duplicate tid. gettid(2) bug? Seeing this would be very upsetting. ASSERT_TRUE(tids.find(tid) == tids.end()); - // Uninitialized guard. Our bug. Note this is potentially flaky; we _could_ get - // four random zero bytes, but it should be vanishingly unlikely. - ASSERT_NE(guard, 0U); + // Uninitialized guard. Our bug. Note this is potentially flaky; we _could_ + // get four random zero bytes, but it should be vanishingly unlikely. + ASSERT_NE(guard, nullptr); + +#if defined(__BIONIC__) + // bionic always has the global too. + ASSERT_EQ(__stack_chk_guard, reinterpret_cast(guard)); +#endif tids.insert(tid); guards.insert(guard); } }; -static void* ThreadGuardHelper(void* arg) { - stack_protector_checker* checker = reinterpret_cast(arg); - checker->Check(); - return NULL; -} -#endif // __i386__ - TEST(stack_protector, same_guard_per_thread) { -#if defined(__i386__) + // Everyone has the TLS slot set, even if their stack protector + // implementation doesn't yet use it. stack_protector_checker checker; - size_t thread_count = 10; - for (size_t i = 0; i < thread_count; ++i) { + + // Check the main thread. + ASSERT_EQ(getpid(), gettid()); // We are the main thread, right? + checker.Check(); + + size_t thread_count = 9; + for (size_t i = 1; i < thread_count; ++i) { pthread_t t; - ASSERT_EQ(0, pthread_create(&t, NULL, ThreadGuardHelper, &checker)); + ASSERT_EQ(0, pthread_create(&t, NULL, [](void* arg) -> void* { + stack_protector_checker* checker = reinterpret_cast(arg); + checker->Check(); + return nullptr; + }, &checker)); void* result; ASSERT_EQ(0, pthread_join(t, &result)); ASSERT_EQ(NULL, result); } ASSERT_EQ(thread_count, checker.tids.size()); - // bionic and glibc use the same guard for every thread. + // Both bionic and glibc use the same guard for every thread. ASSERT_EQ(1U, checker.guards.size()); -#else // __i386__ - GTEST_LOG_(INFO) << "This test does nothing.\n"; -#endif // __i386__ } -// For ARM and MIPS, glibc has a global stack check guard value. -#if defined(__BIONIC__) || defined(__arm__) || defined(__mips__) -#define TEST_STACK_CHK_GUARD - -// Bionic has the global for x86 too, to support binaries that can run on -// Android releases that didn't implement the TLS guard value. -extern "C" uintptr_t __stack_chk_guard; - -/* - * When this function returns, the stack canary will be inconsistent - * with the previous value, which will generate a call to __stack_chk_fail(), - * eventually resulting in a SIGABRT. - * - * This must be marked with "__attribute__ ((noinline))", to ensure the - * compiler generates the proper stack guards around this function. - */ -static char* dummy_buf; - -__attribute__ ((noinline)) -static void do_modify_stack_chk_guard() { - char buf[128]; - // Store local array's address to global variable to force compiler to generate stack guards. - dummy_buf = buf; - __stack_chk_guard = 0x12345678; -} - -#endif - TEST(stack_protector, global_guard) { -#if defined(TEST_STACK_CHK_GUARD) +#if defined(__BIONIC__) + // Bionic always has a global, even if it's using TLS. ASSERT_NE(0, gettid()); ASSERT_NE(0U, __stack_chk_guard); -#else // TEST_STACK_CHK_GUARD - GTEST_LOG_(INFO) << "This test does nothing.\n"; -#endif // TEST_STACK_CHK_GUARD +#else + GTEST_LOG_(INFO) << "glibc doesn't have a global __stack_chk_guard.\n"; +#endif } class stack_protector_DeathTest : public BionicDeathTest {}; TEST_F(stack_protector_DeathTest, modify_stack_protector) { -#if defined(TEST_STACK_CHK_GUARD) - ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), ""); -#else // TEST_STACK_CHK_GUARD - GTEST_LOG_(INFO) << "This test does nothing.\n"; -#endif // TEST_STACK_CHK_GUARD + // In another file to prevent inlining, which removes stack protection. + extern void modify_stack_protector_test(); + ASSERT_EXIT(modify_stack_protector_test(), + testing::KilledBySignal(SIGABRT), "stack corruption detected"); } diff --git a/tests/stack_protector_test_helper.cpp b/tests/stack_protector_test_helper.cpp new file mode 100644 index 000000000..34f3c7726 --- /dev/null +++ b/tests/stack_protector_test_helper.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Deliberately overwrite the stack canary. +__attribute__((noinline)) void modify_stack_protector_test() { + char buf[128]; + // We can't use memset here because it's fortified, and we want to test + // the line of defense *after* that. + char* p = buf; + while ((p - buf) < static_cast(sizeof(buf) + sizeof(void*))) *p++ = '\0'; +} -- cgit v1.2.3