Merge branch 'aslr'

This commit is contained in:
Pawel Dziepak
2013-04-17 20:07:32 +02:00
87 changed files with 956 additions and 348 deletions
+8 -5
View File
@@ -73,11 +73,14 @@ typedef struct area_info {
#define B_32_BIT_CONTIGUOUS 6 /* B_CONTIGUOUS, < 4 GB physical address */
/* address spec for create_area(), and clone_area() */
#define B_ANY_ADDRESS 0
#define B_EXACT_ADDRESS 1
#define B_BASE_ADDRESS 2
#define B_CLONE_ADDRESS 3
#define B_ANY_KERNEL_ADDRESS 4
#define B_ANY_ADDRESS 0
#define B_EXACT_ADDRESS 1
#define B_BASE_ADDRESS 2
#define B_CLONE_ADDRESS 3
#define B_ANY_KERNEL_ADDRESS 4
/* B_ANY_KERNEL_BLOCK_ADDRESS 5 */
#define B_RANDOMIZED_ANY_ADDRESS 6
#define B_RANDOMIZED_BASE_ADDRESS 7
/* area protection */
#define B_READ_AREA 1
@@ -25,7 +25,7 @@
#define USER_SIZE (0x80000000 - (0x10000 + 0x100000))
#define USER_TOP (USER_BASE + (USER_SIZE - 1))
#define KERNEL_USER_DATA_BASE 0x6fff0000
#define KERNEL_USER_DATA_BASE 0x60000000
#define USER_STACK_REGION 0x70000000
#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1)
@@ -25,7 +25,7 @@
#define USER_SIZE (0x80000000 - (0x10000 + 0x100000))
#define USER_TOP (USER_BASE + (USER_SIZE - 1))
#define KERNEL_USER_DATA_BASE 0x6fff0000
#define KERNEL_USER_DATA_BASE 0x60000000
#define USER_STACK_REGION 0x70000000
#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1)
@@ -28,7 +28,7 @@
#define USER_SIZE (0x80000000 - (0x10000 + 0x100000))
#define USER_TOP (USER_BASE + (USER_SIZE - 1))
#define KERNEL_USER_DATA_BASE 0x6fff0000
#define KERNEL_USER_DATA_BASE 0x60000000
#define USER_STACK_REGION 0x70000000
#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1)
@@ -25,7 +25,7 @@
#define USER_SIZE (0x80000000 - (0x10000 + 0x100000))
#define USER_TOP (USER_BASE + (USER_SIZE - 1))
#define KERNEL_USER_DATA_BASE 0x6fff0000
#define KERNEL_USER_DATA_BASE 0x60000000
#define USER_STACK_REGION 0x70000000
#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1)
@@ -39,6 +39,11 @@
#define IA32_MSR_EFER 0xc0000080
// MSR EFER bits
// reference
#define IA32_MSR_EFER_SYSCALL (1 << 0)
#define IA32_MSR_EFER_NX (1 << 11)
// x86_64 MSRs.
#define IA32_MSR_STAR 0xc0000081
#define IA32_MSR_LSTAR 0xc0000082
@@ -131,6 +136,13 @@
#define IA32_FEATURE_AMD_EXT_3DNOWEXT (1 << 30) // 3DNow! extensions
#define IA32_FEATURE_AMD_EXT_3DNOW (1 << 31) // 3DNow!
// some of the features from cpuid eax 0x80000001, edx register (AMD) are also
// available on Intel processors
#define IA32_FEATURES_INTEL_EXT (IA32_FEATURE_AMD_EXT_SYSCALL \
| IA32_FEATURE_AMD_EXT_NX \
| IA32_FEATURE_AMD_EXT_RDTSCP \
| IA32_FEATURE_AMD_EXT_LONG)
// x86 defined features from cpuid eax 6, eax register
// reference http://www.intel.com/Assets/en_US/PDF/appnote/241618.pdf (Table 5-11)
#define IA32_FEATURE_DTS (1 << 0) //Digital Thermal Sensor
@@ -48,8 +48,8 @@
#define USER_SIZE (0x800000000000 - 0x200000)
#define USER_TOP (USER_BASE + (USER_SIZE - 1))
#define KERNEL_USER_DATA_BASE 0x7fffefff0000
#define USER_STACK_REGION 0x7ffff0000000
#define KERNEL_USER_DATA_BASE 0x7f0000000000
#define USER_STACK_REGION 0x7f0000000000
#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1)
@@ -76,7 +76,7 @@
#define USER_SIZE (KERNEL_BASE - 0x10000)
#define USER_TOP (USER_BASE + (USER_SIZE - 1))
#define KERNEL_USER_DATA_BASE 0x6fff0000
#define KERNEL_USER_DATA_BASE 0x60000000
#define USER_STACK_REGION 0x70000000
#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1)
+2 -1
View File
@@ -18,8 +18,9 @@ extern "C" {
status_t commpage_init(void);
status_t commpage_init_post_cpus(void);
void* allocate_commpage_entry(int entry, size_t size);
void* fill_commpage_entry(int entry, const void* copyFrom, size_t size);
addr_t fill_commpage_entry(int entry, const void* copyFrom, size_t size);
image_id get_commpage_image();
area_id clone_commpage_area(team_id team, void** address);
// implemented in the architecture specific part
status_t arch_commpage_init(void);
+1
View File
@@ -52,6 +52,7 @@ struct signal_frame_data {
int32 thread_flags;
uint64 syscall_restart_return_value;
uint8 syscall_restart_parameters[SYSCALL_RESTART_PARAMETER_SIZE];
void* commpage_address;
};
+2
View File
@@ -259,6 +259,8 @@ struct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
size_t used_user_data;
struct free_user_thread* free_user_threads;
void* commpage_address;
struct team_debug_info debug_info;
// protected by scheduler lock
+87
View File
@@ -0,0 +1,87 @@
/*
* Copyright 2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Paweł Dziepak, pdziepak@quarnos.org
*/
#ifndef KERNEL_UTIL_RANDOM_H
#define KERNEL_UTIL_RANDOM_H
#include <smp.h>
#include <SupportDefs.h>
#define MAX_FAST_RANDOM_VALUE 0x7fff
#define MAX_RANDOM_VALUE 0x7fffffffu
#define MAX_SECURE_RANDOM_VALUE 0xffffffffu
static const int kFastRandomShift = 15;
static const int kRandomShift = 31;
static const int kSecureRandomShift = 32;
#ifdef __cplusplus
extern "C" {
#endif
unsigned int fast_random_value(void);
unsigned int random_value(void);
unsigned int secure_random_value(void);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
template<typename T>
T
fast_get_random()
{
size_t shift = 0;
T random = 0;
while (shift < sizeof(T) * 8) {
random |= (T)fast_random_value() << shift;
shift += kFastRandomShift;
}
return random;
}
template<typename T>
T
get_random()
{
size_t shift = 0;
T random = 0;
while (shift < sizeof(T) * 8) {
random |= (T)random_value() << shift;
shift += kRandomShift;
}
return random;
}
template<typename T>
T
secure_get_random()
{
size_t shift = 0;
T random = 0;
while (shift < sizeof(T) * 8) {
random |= (T)secure_random_value() << shift;
shift += kSecureRandomShift;
}
return random;
}
#endif // __cplusplus
#endif // KERNEL_UTIL_RANDOM_H
+2
View File
@@ -121,6 +121,8 @@ status_t vm_delete_area(team_id teamID, area_id areaID, bool kernel);
status_t vm_create_vnode_cache(struct vnode *vnode, struct VMCache **_cache);
status_t vm_set_area_memory_type(area_id id, phys_addr_t physicalBase,
uint32 type);
status_t vm_set_area_protection(team_id team, area_id areaID,
uint32 newProtection, bool kernel);
status_t vm_get_page_mapping(team_id team, addr_t vaddr, phys_addr_t *paddr);
bool vm_test_map_modification(struct vm_page *page);
void vm_clear_map_flags(struct vm_page *page, uint32 flags);
+1 -1
View File
@@ -28,7 +28,7 @@ extern "C" {
// Should only be used by vm internals
status_t vm_page_fault(addr_t address, addr_t faultAddress, bool isWrite,
bool isUser, addr_t *newip);
bool isExecute, bool isUser, addr_t *newip);
void vm_unreserve_memory(size_t bytes);
status_t vm_try_reserve_memory(size_t bytes, int priority, bigtime_t timeout);
status_t vm_daemon_init(void);
+1 -1
View File
@@ -34,7 +34,7 @@ void __init_env(const struct user_space_program_args *args);
void __init_heap(void);
void __init_heap_post_env(void);
void __init_time(void);
void __init_time(addr_t commPageTable);
void __arch_init_time(struct real_time_data *data, bool setDefaults);
bigtime_t __arch_get_system_time_offset(struct real_time_data *data);
bigtime_t __get_system_time_offset();
@@ -51,6 +51,7 @@ struct rld_export {
void (*call_termination_hooks)();
const struct user_space_program_args *program_args;
const void* commpage_address;
};
extern struct rld_export *__gRuntimeLoader;
@@ -12,8 +12,4 @@
//#define COMMPAGE_ENTRY_M68K_SYSCALL (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)
//#define COMMPAGE_ENTRY_M68K_MEMCPY (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
/* 0xffff0000 colides with IO space mapped with TT1 on Atari */
#warning ARM: determine good place for compage..
#define ARCH_USER_COMMPAGE_ADDR (0xfeff0000)
#endif /* _SYSTEM_ARCH_M68K_COMMPAGE_DEFS_H */
@@ -12,7 +12,4 @@
#define COMMPAGE_ENTRY_M68K_SYSCALL (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)
#define COMMPAGE_ENTRY_M68K_MEMCPY (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
/* 0xffff0000 colides with IO space mapped with TT1 on Atari */
#define ARCH_USER_COMMPAGE_ADDR (0xfeff0000)
#endif /* _SYSTEM_ARCH_M68K_COMMPAGE_DEFS_H */
@@ -14,7 +14,5 @@
#define COMMPAGE_ENTRY_MIPSEL_SYSCALL (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)
#define COMMPAGE_ENTRY_MIPSEL_MEMCPY (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
#define ARCH_USER_COMMPAGE_ADDR (0xffff0000)
#endif /* _SYSTEM_ARCH_MIPSEL_COMMPAGE_DEFS_H */
@@ -12,6 +12,4 @@
#define COMMPAGE_ENTRY_PPC_SYSCALL (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 0)
#define COMMPAGE_ENTRY_PPC_MEMCPY (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
#define ARCH_USER_COMMPAGE_ADDR (0xffff0000)
#endif /* _SYSTEM_ARCH_PPC_COMMPAGE_DEFS_H */
@@ -16,7 +16,7 @@
(COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 3)
#define COMMPAGE_ENTRY_X86_SIGNAL_HANDLER_BEOS \
(COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 4)
#define ARCH_USER_COMMPAGE_ADDR (0xffff0000)
#define COMMPAGE_ENTRY_X86_THREAD_EXIT \
(COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 5)
#endif /* _SYSTEM_ARCH_x86_COMMPAGE_DEFS_H */
@@ -13,7 +13,7 @@
#define COMMPAGE_ENTRY_X86_MEMSET (COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 1)
#define COMMPAGE_ENTRY_X86_SIGNAL_HANDLER \
(COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 2)
#define ARCH_USER_COMMPAGE_ADDR (0xffffffffffff0000)
#define COMMPAGE_ENTRY_X86_THREAD_EXIT \
(COMMPAGE_ENTRY_FIRST_ARCH_SPECIFIC + 3)
#endif /* _SYSTEM_ARCH_x86_64_COMMPAGE_DEFS_H */
-5
View File
@@ -19,11 +19,6 @@
#define COMMPAGE_SIGNATURE 'COMM'
#define COMMPAGE_VERSION 1
#define USER_COMMPAGE_ADDR ARCH_USER_COMMPAGE_ADDR
// set by the architecture specific implementation
#define USER_COMMPAGE_TABLE ((void**)(USER_COMMPAGE_ADDR))
#include <arch_commpage_defs.h>
#endif /* _SYSTEM_COMMPAGE_DEFS_H */
+1 -1
View File
@@ -15,7 +15,7 @@
#define USER_STACK_GUARD_SIZE (4 * B_PAGE_SIZE) // 16 kB
#define USER_MAIN_THREAD_STACK_SIZE (16 * 1024 * 1024) // 16 MB
#define USER_STACK_SIZE (256 * 1024) // 256 kB
#define MIN_USER_STACK_SIZE (4 * 1024) // 4 KB
#define MIN_USER_STACK_SIZE (8 * 1024) // 8 kB
#define MAX_USER_STACK_SIZE (16 * 1024 * 1024) // 16 MB