Skip to content

Failure with 0 aslr_slide #79

@liamwhite

Description

@liamwhite

This code does not work when ASLR is disabled or you hit the 1/260000 lottery of selecting a 0 ASLR slide value:

// search for applicable space for inline hook JIT
auto cur_searching_addr =
skyline::utils::g_MainTextAddr - inline_hook_pool_size; // start searching from right before .text
MemoryInfo mem;
while (true) {
u32 page_info;
if (R_SUCCEEDED(svcQueryMemory(&mem, &page_info, cur_searching_addr)) && mem.type == MemType_Unmapped &&
mem.size >= ALIGN_UP(inline_hook_pool_size, PAGE_SIZE)) {
break;
}
cur_searching_addr -= PAGE_SIZE;
}
// allocate inline hook JIT
rc = jitCreate(&__inline_hook_jit, (void*)ALIGN_DOWN(mem.addr + mem.size - inline_hook_pool_size, PAGE_SIZE),
inline_hook_pool_size);

The code assumes addresses before the first .text section can be mapped as generated code. But if the ASLR slide is 0, then they are not mappable as generated code, and the program will fail to perform the call to svc::ControlCodeMemory and subsequently crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions