diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2015-06-30 15:10:51 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2015-06-30 18:45:59 -0700 |
commit | f643eb38c36eb63f612e20dea09fd43ac6a6b360 (patch) | |
tree | b3ecf22ae61f55e3cd37bb04f65d16af2bb16e44 /libc/bionic | |
parent | 754f669076ec1edfc0d597aaf89600d4c93f9a7c (diff) | |
download | bionic-f643eb38c36eb63f612e20dea09fd43ac6a6b360.zip bionic-f643eb38c36eb63f612e20dea09fd43ac6a6b360.tar.gz bionic-f643eb38c36eb63f612e20dea09fd43ac6a6b360.tar.bz2 |
Improve personality initialization
1. Personality parameter should be unsigned int (not long)
2. Do not reset bits outside of PER_MASK when setting
personality value.
3. Set personality for static executables.
Bug: http://b/21900686
Change-Id: I4c7e34079cbd59b818ce221eed325c05b9bb2303
Diffstat (limited to 'libc/bionic')
-rw-r--r-- | libc/bionic/libc_init_common.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp index 9b23ece..bd71628 100644 --- a/libc/bionic/libc_init_common.cpp +++ b/libc/bionic/libc_init_common.cpp @@ -37,6 +37,7 @@ #include <stdlib.h> #include <string.h> #include <sys/auxv.h> +#include <sys/personality.h> #include <sys/time.h> #include <unistd.h> @@ -44,6 +45,7 @@ #include "private/bionic_ssp.h" #include "private/bionic_tls.h" #include "private/KernelArgumentBlock.h" +#include "private/libc_logging.h" #include "pthread_internal.h" extern "C" abort_msg_t** __abort_message_ptr; @@ -289,6 +291,19 @@ static void __sanitize_environment_variables(char** env) { dst[0] = nullptr; } +static void __initialize_personality() { +#if !defined(__LP64__) + int old_value = personality(0xffffffff); + if (old_value == -1) { + __libc_fatal("error getting old personality value: %s", strerror(errno)); + } + + if (personality((static_cast<unsigned int>(old_value) & ~PER_MASK) | PER_LINUX32) == -1) { + __libc_fatal("error setting PER_LINUX32 personality: %s", strerror(errno)); + } +#endif +} + void __libc_init_AT_SECURE(KernelArgumentBlock& args) { __libc_auxv = args.auxv; @@ -312,6 +327,8 @@ void __libc_init_AT_SECURE(KernelArgumentBlock& args) { // Now the environment has been sanitized, make it available. environ = args.envp; + + __initialize_personality(); } /* This function will be called during normal program termination |