[php-src] Issue #14083: Heap hardening

From: Date: Tue, 30 Apr 2024 12:48:11 +0000
Subject: [php-src] Issue #14083: Heap hardening
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246839@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14083 Author: jvoisin ### Description Currently, PHP's heap implementation is ~trivial to exploit: - [BlackAlps 2022: Generic Remote Exploit Techniques For The PHP Allocator, And 0days by Charles Fol](https://www.youtube.com/watch?v=-FXvUe0tySM) - [SSD Advisory – PHP SplDoublyLinkedList UAF Sandbox Escape](https://ssd-disclosure.com/ssd-advisory-php-spldoublylinkedlist-uaf-sandbox-escape/) - [Gollum: Modular and Greybox Exploit Generation for Heap Overflows in Interpreters ](https://dl.acm.org/doi/10.1145/3319535.3354224) - [In the land of PHP you will always be (use-after-)free](https://adepts.of0x.cc/challenge01-php-uaf/) and [Solution to Adepts of 0xCC Challenge 01](https://gist.github.com/kachakil/17ea369f5372e51f37ff825345fd9248) - [mm0r1's exploits](https://github.com/mm0r1/exploits/tree/master) There are several hardening techniques that could/should be implemented, listed here in order of difficulty: - [x] prevent [unlink](https://ir0nstone.gitbook.io/notes/types/heap/unlink-exploit) abuse: #13943 - [ ] prevent freelist-corruption via shadow-pointer à la [XNU](https://github.com/apple-oss-distributions/xnu/blob/xnu-6153.141.1/osfmk/kern/zalloc.c#L134)/[linux](https://github.com/torvalds/linux/blob/c942a0cd3603e34dd2d7237e064d9318cb7f9654/mm/slub.c#L485)/[partitionAlloc](https://chromium.googlesource.com/chromium/src/+/master/base/allocator/partition_allocator/PartitionAlloc.md)/suhosin/…: #14054 - [ ] surround large allocations with guard-pages, as done in [partitionAlloc](https://chromium.googlesource.com/chromium/src/+/master/base/allocator/partition_allocator/PartitionAlloc.md), [scudo](https://source.android.com/docs/security/test/scudo/), … - [ ] isolate types in different heaps to make type confusion/use after free more difficult, as in [kalloc_type](https://security.apple.com/blog/towards-the-next-generation-of-xnu-memory-safety/). An additional benefit of type isolation + freelist bitmap is that we wouldn't need the object_store anymore to enumerate objects. A less invasive approach would be to simply isolate by size as done in [partitionAlloc](https://chromium.googlesource.com/chromium/src/+/master/base/allocator/partition_allocator/PartitionAlloc.md) - once this is done, heaps need to be pinned by size/type, to prevent an attacker from re-using the memory space of a destructed heap with one of different type/size. - [ ] allocate strings and array buckets in [GigaCages](https://labs.withsecure.com/publications/some-brief-notes-on-webkit-heap-hardening) so that a corrupt length doesn't allow to access anything else than other strings/array buckets. This will significantly increase the virtual-memory usage though.

« previous php.bugs (#246839) next »