Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mach_override.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Beer <ian.beer@chromium.org>2013-11-25 19:14:22 +0400
committerIan Beer <ian.beer@chromium.org>2013-11-25 19:14:22 +0400
commit616d2ad5ed35ab0716b9457e8845e226948ffc88 (patch)
treef1bf96417184d665924e15d0c96ba89a90c6d338
parentfa80645b038a6a1af445cc2afba519603e425116 (diff)
add 64-bit randomization
-rw-r--r--Rakefile6
-rw-r--r--mach_override.c24
2 files changed, 17 insertions, 13 deletions
diff --git a/Rakefile b/Rakefile
index 167402a..974d172 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,12 +1,14 @@
desc 'Build'
task :build do
system('mkdir build')
- system('gcc -o build/test_gcc_i386 -framework CoreServices *.c *.cp libudis86/*.c')
+ system('gcc -g -o build/test_gcc_i386 -m32 -framework CoreServices *.c *.cp libudis86/*.c')
+ system('gcc -g -o build/test_gcc_x86_64 -m64 -framework CoreServices *.c *.cp libudis86/*.c')
end
desc 'Test'
task :test do
system('build/test_gcc_i386')
+ system('build/test_gcc_x86_64')
end
desc 'Clean up'
@@ -14,4 +16,4 @@ task :clean do
system('rm -rf build')
end
-task :default => [:build, :test] \ No newline at end of file
+task :default => [:build, :test]
diff --git a/mach_override.c b/mach_override.c
index 2224571..c8a9857 100644
--- a/mach_override.c
+++ b/mach_override.c
@@ -390,27 +390,29 @@ allocateBranchIsland(
assert( island );
mach_error_t err = err_none;
-#if defined(__i386__)
- vm_address_t page = 0;
- err = vm_allocate( mach_task_self(), &page, kPageSize, VM_FLAGS_ANYWHERE );
- if( err == err_none )
- *island = (BranchIsland*) page;
- return err;
-#else
+
if( allocateHigh ) {
vm_size_t pageSize;
err = host_page_size( mach_host_self(), &pageSize );
if( !err ) {
assert( sizeof( BranchIsland ) <= pageSize );
+ vm_address_t page = 0;
+#if defined(__i386__)
+ err = vm_allocate( mach_task_self(), &page, pageSize, VM_FLAGS_ANYWHERE );
+ if( err == err_none )
+ *island = (BranchIsland*) page;
+#else
+
#if defined(__ppc__) || defined(__POWERPC__)
vm_address_t first = 0xfeffffff;
vm_address_t last = 0xfe000000 + pageSize;
#elif defined(__x86_64__)
- vm_address_t first = ((uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1)) | ((uint64_t)1 << 31); // start in the middle of the page?
- vm_address_t last = 0x0;
+ // 64-bit ASLR is in bits 13-28
+ vm_address_t first = (uint64_t)originalFunctionAddress & ~( (0xFUL << 28) | (pageSize - 1) ) | (0x1UL << 31);
+ vm_address_t last = (uint64_t)originalFunctionAddress & ~((0x1UL << 32) - 1);
#endif
- vm_address_t page = first;
+ page = first;
int allocated = 0;
vm_map_t task_self = mach_task_self();
@@ -432,6 +434,7 @@ allocateBranchIsland(
*island = (BranchIsland*) page;
else if( !allocated && !err )
err = KERN_NO_SPACE;
+#endif
}
} else {
void *block = malloc( sizeof( BranchIsland ) );
@@ -443,7 +446,6 @@ allocateBranchIsland(
if( !err )
(**island).allocatedHigh = allocateHigh;
return err;
-#endif
}
/*******************************************************************************