Android 5.0的ASLR

非常好的一篇英文文章The State of ASLR on Android Lollipop,有机会全部翻译一下。
重点如下:

Brief history of ASLR on Android

Early Android versions only had stack randomization due to lack of kernel support for ASLR on ARM. The 4.0 release introduced mmap randomization thanks to upstream progress. The kernel also gained support for ARM exec and brk randomization but Android still lacked userspace support. The 4.1 release introduced support for full ASLR by enabling heap (brk) randomization and adding linker support for self-relocation and Position Independent Executables (PIE).

Lollipop is the latest step forwards, as non-PIE executable support was dropped and all processes now have full ASLR.

The generated code has a hard-wired base address just like native binaries, and is always relocated by default on a production Android system. Since this occurs in userspace, the Android Runtime code is responsible for choosing an address. The main base image is currently chosen by applying a delta generated with the following code to the base address:

std::default_random_engine generator;
generator.seed(NanoTime() * getpid());
std::uniform_int_distribution<int32_t> distribution(min_delta, max_delta);

In Lollipop, Android moved to a compacting garbage collector as part of replacing Dalvik with the new Android Runtime (ART) but still uses dlmalloc to implement a separate garbage collected heap for the remaining non-movable objects. The malloc implementation in Bionic was replaced with jemalloc for improved performance and scalability along with with lower fragmentation and lazy purging of unused page spans.

Unlike dlmalloc, jemalloc does reduce heap randomization entropy. It’s a side effect of the low-level chunk allocation model, where all memory is allocated via naturally aligned chunks of the same size. The jemalloc version used in the current release of Lollipop uses 4MiB chunks (4MiB aligned) while the upcoming release will use 256kiB chunks (256kiB aligned) due to changes in the upstream jemalloc design (for reasons unrelated to ASLR). With 4MiB chunks, it loses 10 bits of ASLR entropy relative to 4k page granularity (2^12 -> 2^22) while the new default chunk size causes a less severe 6-bit loss of entropy.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、感恩父母,感恩父母替我照顾孩子,感恩父亲送我上班,感恩妈妈帮我洗衣服!谢谢你们!我爱你们! 2、感恩金钱,因为...
    海清_3a07阅读 181评论 0 2
  • ios 获取系统当前时间 前言 在开发中,我们常常需要获取系统当前时间,然后对时间进行操作,下面我介绍几种获取时间...
    少年_如他阅读 11,664评论 7 5
  • # 数日之后的重逢 今天,我终于开始更新我的微信公众号了!(虽然不知道下次更新是啥时候)好在观众有限,而且又都是知...
    Gardield0402阅读 173评论 0 0
  • 朝牧南山牛,暮听泉溪流。 午时蝉声唱,夜半鹧鸪愁。 或问何以知,久闻遂音熟。 渐会境中意,声声催快锄。 戮力禾苗希...
    叶落岁暮阅读 389评论 4 11
  • 摇舟击棹奔流上,卷浪翻波。槌鼓敲锣,虎臂雄挥竞渡河。 羞容娇女花阴处,尽望情哥。过往如梭,翘首凝眸疾步挪。
    泓颖阅读 288评论 6 6