linux - mmap() 熵的 ASLR 位

标签 linux linux-kernel kernel mmap aslr

我正在研究 x86 系统上 mmap() 的 ASLR 随机化。 我在很多地方读到,用mmap()加载的地址有16位的随机化。

但是在源码中我发现:

static unsigned long mmap_rnd(void)
02  {
03          unsigned long rnd = 0;
04   
05         /*
06          *  8 bits of randomness in 32bit mmaps, 20 address space bits
07          * 28 bits of randomness in 64bit mmaps, 40 address space bits
08          */
09          if (current->flags & PF_RANDOMIZE) {
10                  if (mmap_is_ia32())
11                          rnd = (long)get_random_int() % (1<<8);
12                  else 
13                          rnd = (long)(get_random_int() % (1<<28));
14          }
15          return rnd << PAGE_SHIFT;
16  }

所以,那将只有 8 位随机性。

但实际上,运行一些测试,我得到以下地址(stack-heap-mmap) bf937000,09a60000,b774b000

bfa86000,090ef000,b76e2000

如果能b77XX000和b76XX000就超过16位了!!!

有什么帮助吗?

最佳答案

PAGE_SHIFT 正在将随机性转移到不同的位位置。您的 mmap 地址之间的区别确实是:

 b774b000
-b76e2000
---------
    69000

我不知道 PAGE_SHIFT 的值是多少,但是如果它是 12,那么你就有 0x69 的差异,完全适合 8 位。

关于linux - mmap() 熵的 ASLR 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13826479/

相关文章:

windows - 使用 WinDbg 设置远程内核调试器

Linux 内核中的 current_thread_info() 内联函数?

operating-system - 内核高内存

linux - cmake execute_process 找不到源命令

C++ Linux 到 Windows 交叉编译错误

linux-kernel - 让模拟 pmem 工作并创 build 备

linux - source insight 中的汇编代码支持

php - 连接到在 Ubuntu AWS 实例中创建的 MySQL 数据库

c++ - 以编程方式清除 Linux 中已安装 (SSD) 磁盘上的缓存

android-emulator - 将新编译的 Linux 内核镜像加载到 android 模拟器 (1.5) 时出错