简体   繁体   English

为什么 macOS 上的动态链接库似乎禁用了 ASLR?

[英]Why does ASLR appear to be disabled for dynamically-linked libraries on macOS?

If I'm not mistaken, the following code should print out different addresses every time it's run.如果我没记错的话,下面的代码每次运行时应该打印出不同的地址。 However, it always displays the same address for isupper (for example).但是,它始终显示isupper的相同地址(例如)。

Code:代码:

#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char *argv[]) {
   printf("isspace @ %p\n", dlsym(RTLD_DEFAULT, "isspace"));
   return 0;
}

Output: Output:

$ ./libc-simple 
isspace @ 0x7fff76b63035
$ ./libc-simple 
isspace @ 0x7fff76b63035
$ ./libc-simple 
isspace @ 0x7fff76b63035
$ ./libc-simple 
isspace @ 0x7fff76b63035

(I'm running macOS 10.14.6, but I tested the same code on another computer running macOS 10.15 with the same result.) (我运行的是 macOS 10.14.6,但我在另一台运行 macOS 10.15 的计算机上测试了相同的代码,结果相同。)

What am I missing?我错过了什么?

As an optimization, macOS uses a shared mapping for a lot of the system libraries.作为一种优化,macOS 为许多系统库使用共享映射。 They are loaded once at boot and used by all processes.它们在启动时加载一次并被所有进程使用。 For a given boot, the address is constant across all such processes.对于给定的引导,地址在所有此类进程中都是恒定的。 However, the address is randomized each boot for security.但是,为了安全起见,地址在每次引导时都是随机的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM