Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2120)

Unified Diff: base/android/linker/linker_jni.cc

Issue 470053003: Switch from local random address generation to kernel ASLR (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment typo Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/android/java/src/org/chromium/base/library_loader/Linker.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/linker/linker_jni.cc
diff --git a/base/android/linker/linker_jni.cc b/base/android/linker/linker_jni.cc
index b0b464b0d4eb8f2d1fb6292eccf89387959ac241..4eb774b69ab9fd88e38022f0192787bee9a6177f 100644
--- a/base/android/linker/linker_jni.cc
+++ b/base/android/linker/linker_jni.cc
@@ -17,6 +17,7 @@
#include <crazy_linker.h>
#include <jni.h>
#include <stdlib.h>
+#include <sys/mman.h>
#include <unistd.h>
// Set this to 1 to enable debug traces to the Android log.
@@ -560,10 +561,16 @@ jboolean CanUseSharedRelro(JNIEnv* env, jclass clazz) {
return crazy_system_can_share_relro();
}
-jlong GetPageSize(JNIEnv* env, jclass clazz) {
- jlong result = static_cast<jlong>(sysconf(_SC_PAGESIZE));
- LOG_INFO("%s: System page size is %lld bytes\n", __FUNCTION__, result);
- return result;
+jlong GetRandomBaseLoadAddress(JNIEnv* env, jclass clazz, jlong bytes) {
+ void* address =
+ mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (address == MAP_FAILED) {
+ LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__);
+ return 0;
+ }
+ munmap(address, bytes);
+ LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address);
+ return static_cast<jlong>(reinterpret_cast<intptr_t>(address));
}
const JNINativeMethod kNativeMethods[] = {
@@ -610,11 +617,12 @@ const JNINativeMethod kNativeMethods[] = {
")"
"Z",
reinterpret_cast<void*>(&CanUseSharedRelro)},
- {"nativeGetPageSize",
+ {"nativeGetRandomBaseLoadAddress",
"("
+ "J"
")"
"J",
- reinterpret_cast<void*>(&GetPageSize)}, };
+ reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, };
} // namespace
« no previous file with comments | « base/android/java/src/org/chromium/base/library_loader/Linker.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698