据我所知,ASLR有三种模式:
brk()-allocated内存,据我所知,主要来自小malloc()-calls。为什么有一个额外的模式,特别是对于brk()-allocated内存(如果这是它所做的一切),它有多重要,或者更确切地说,什么时候使用模式2而不是模式1很重要?
发布于 2020-05-21 03:40:59
还必须有一种特定的随机化brk()的方法,因为除了glibc的默认(ptmalloc)之外,还有一些堆实现可能不依赖于brk(),如果只使用va_randomize_space = 1,则直接使用brk()不受保护地使用可预测的地址空间。
这一点也很重要,因为攻击者可以使用直接的SYS_brk系统调用来创建外壳代码,从而将内存映射为可以使用的预测地址空间。
如果快速查看Linux内核源代码,建议将ASLR设置为模式2,只会做到这一点:将动态内存映射地址空间的开始随机化:
https://github.com/torvalds/linux/blob/master/fs/binfmt_Elf.c#L 1110-L 1123
<!-- language: lang-c -->
if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) {
/*
* For architectures with ELF randomization, when executing
* a loader directly (i.e. no interpreter listed in ELF
* headers), move the brk area out of the mmap region
* (since it grows up, and may collide early with the stack
* growing down), and into the unused ELF_ET_DYN_BASE region.
*/
if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) &&
elf_ex->e_type == ET_DYN && !interpreter) {
mm->brk = mm->start_brk = ELF_ET_DYN_BASE;
}
mm->brk = mm->start_brk = arch_randomize_brk(mm);
#ifdef compat_brk_randomized
current->brk_randomized = 1;
#endif
}https://github.com/torvalds/linux/blob/master/mm/mmap.c#L212-L213
<!-- language: lang-c -->
if (current->brk_randomized)
min_brk = mm->start_brk;https://security.stackexchange.com/questions/229443
复制相似问题