Skip to content

Commit

Permalink
Process ASLR support
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 14, 2019
1 parent 96d3cd9 commit 4737a48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/process/include/process.hpp
Expand Up @@ -28,6 +28,7 @@ class Process {
List<ProcessSymbol> symbols;
uintptr_t entry;
void addPage(uintptr_t vaddr, void* paddr, uint8_t flags);
uintptr_t _aslrCode, _aslrStack;

public:
Process();
Expand Down
12 changes: 9 additions & 3 deletions src/process/process.cpp
Expand Up @@ -10,6 +10,8 @@ Process::Process() {
id = -1;
pagetable = 0;
entry = 0;
_aslrCode = ((RAND::get<uintptr_t>() << 12) & 0x7FFFFFFF000) | 0x40000000000;
_aslrStack = ((RAND::get<uintptr_t>() << 12) & 0x7FFFFFFF000) | 0x80000000000;
}
Process::~Process() {
if (pagetable != 0) {
Expand Down Expand Up @@ -92,9 +94,13 @@ uintptr_t Process::addSection(SectionType type, size_t size) {
if (size == 0)
return 0;
size_t pages = (size >> 12) + 1;
uintptr_t vaddr = 0xF000000000;
if (type == SectionTypeStack)
vaddr = 0xA000000000;
uintptr_t vaddr;
if (type != SectionTypeStack) {
vaddr = _aslrCode;
} else {
vaddr = _aslrStack;
}

for (uintptr_t caddr = vaddr; caddr < vaddr + size; caddr += 0x1000) {
if (getPhysicalAddress(vaddr) != 0) {
vaddr += 0x1000;
Expand Down

0 comments on commit 4737a48

Please sign in to comment.