<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theiphonewiki.com/w/index.php?action=history&amp;feed=atom&amp;title=Heap_Hardening</id>
	<title>Heap Hardening - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.theiphonewiki.com/w/index.php?action=history&amp;feed=atom&amp;title=Heap_Hardening"/>
	<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Heap_Hardening&amp;action=history"/>
	<updated>2026-05-17T05:13:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.14</generator>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Heap_Hardening&amp;diff=27207&amp;oldid=prev</id>
		<title>Http: initial page with some infos from mdowd's presentation</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Heap_Hardening&amp;diff=27207&amp;oldid=prev"/>
		<updated>2012-10-16T22:55:30Z</updated>

		<summary type="html">&lt;p&gt;initial page with some infos from mdowd&amp;#039;s presentation&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The Heap has been hardened since iOS6 to prevent well-known attack strategies. Three mitigations were put in place:&lt;br /&gt;
*Pointer validation&lt;br /&gt;
*Block poisoning&lt;br /&gt;
*Freelist integrity verification&lt;br /&gt;
This is specific to the zone allocator (&amp;lt;code&amp;gt;zalloc()&amp;lt;/code&amp;gt;, used by &amp;lt;code&amp;gt;kalloc()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MALLOC()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MALLOC_ZONE()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
===Pointer Validation===&lt;br /&gt;
The goal is to prevent invalid pointers being entered into &amp;lt;code&amp;gt;kalloc()&amp;lt;/code&amp;gt; zone's freelist. Additional checks are performed on pointers passed to &amp;lt;code&amp;gt;zfree()&amp;lt;/code&amp;gt;. This is also performed as part of validation on pointers in freelist during allocation (&amp;lt;code&amp;gt;zalloc()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The pointer is verified to be in kernel memory (&amp;lt;code&amp;gt;0x80000000&amp;lt;/code&amp;gt;-&amp;lt;code&amp;gt;0xFFFEFFFF&amp;lt;/code&amp;gt;). If &amp;lt;code&amp;gt;allows_foreign&amp;lt;/code&amp;gt; is set in zone, no more validation is performed (currently &amp;lt;code&amp;gt;event_zone&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;vm_map_entry_reserved_zone&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;vm_page_zone&amp;lt;/code&amp;gt;). If the pointer is within kernel image, allow, otherwise ensure pointer is within &amp;lt;code&amp;gt;zone_map&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Block poisoning===&lt;br /&gt;
The goal is to prevent UAF-style attacks. The stategy involves filling blocks with sentinel value (&amp;lt;code&amp;gt;0xdeadbeef&amp;lt;/code&amp;gt;) when being freed. This is done by &amp;lt;code&amp;gt;add_to_zone()&amp;lt;/code&amp;gt;, called from &amp;lt;code&amp;gt;zfree()&amp;lt;/code&amp;gt; and only on selected blocks with block sizes smaller than cache line size of processor (32 bytes on A5/A5X devices) and can be overridden with &amp;quot;&amp;lt;code&amp;gt;&amp;amp;#8209;zp&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;&amp;amp;#8209;no&amp;amp;#8209;zp&amp;lt;/code&amp;gt;&amp;quot;, &amp;quot;&amp;lt;code&amp;gt;zp&amp;amp;#8209;factor&amp;lt;/code&amp;gt;&amp;quot; boot parameters.&lt;br /&gt;
&lt;br /&gt;
===Freelist integrity verification===&lt;br /&gt;
The goal is to prevent heap overwrites from being exploitable. Two random values are generated at boot time (&amp;lt;code&amp;gt;zone_bootstrap()&amp;lt;/code&amp;gt;), 32-bit cookie for &amp;quot;poisoned blocks&amp;quot; and 31-bit cookie (low bit cleared) for &amp;quot;non-poisoned blocks&amp;quot;. The value serves as a validation cookie.&lt;br /&gt;
&lt;br /&gt;
The freelist pointers at the top of a free block are since iOS6 validated by &amp;lt;code&amp;gt;zalloc()&amp;lt;/code&amp;gt;. This check is done by &amp;lt;code&amp;gt;alloc_from_zone()&amp;lt;/code&amp;gt;. The encoded next pointer is placed at the end of block XORed with &amp;quot;poisoned_cookie&amp;quot; or &amp;quot;non-poisoned cookie&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;zalloc()&amp;lt;/code&amp;gt; ensures &amp;lt;code&amp;gt;next_pointer&amp;lt;/code&amp;gt; matches the encoded pointer at the end of the block and tries both cookies. If the poisoned cookie matches, it checks the whole block for modification of sentinel (0xdeadbeef) values and kernel panics if either check fails. The next pointer and cookie is replaced by &amp;lt;code&amp;gt;0xdeadbeef&amp;lt;/code&amp;gt; when allocated as possible information leak protection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://conference.hackinthebox.org/hitbsecconf2012kul/materials/D1T2%20-%20Mark%20Dowd%20&amp;amp;amp;%20Tarjei%20Mandt%20-%20iOS6%20Security.pdf Mark Dowd &amp;amp; Tarjei Mandt's iOS6 presentation at HITB 2012 KUL D1T2]&lt;/div&gt;</summary>
		<author><name>Http</name></author>
		
	</entry>
</feed>