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

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: 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
Index: base/android/linker/linker_jni.cc
diff --git a/base/android/linker/linker_jni.cc b/base/android/linker/linker_jni.cc
index be4a5ed30df2c3b6ca99830020bb11835153200b..bf74fc36cf64d1da02b221ca92942ed24c414f79 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.
@@ -566,6 +567,18 @@ jlong GetPageSize(JNIEnv* env, jclass clazz) {
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[] = {
{"nativeLoadLibrary",
"("
@@ -614,7 +627,13 @@ const JNINativeMethod kNativeMethods[] = {
"("
")"
"J",
- reinterpret_cast<void*>(&GetPageSize)}, };
+ reinterpret_cast<void*>(&GetPageSize)},
+ {"nativeGetRandomBaseLoadAddress",
+ "("
+ "J"
+ ")"
+ "J",
+ reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, };
} // namespace

Powered by Google App Engine
This is Rietveld 408576698