SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
5 Minutes with the 

MacOS / iOS Zone Allocator
WhiskeyCon Singapore, March, 2017
| © 2017 by ANTID0TE All rights reserved
Who am I?
• Stefan Esser
• from Germany
• in Information Security since 1998
• SektionEins GmbH from (2007 - 2016)
• Antid0te UG (2013 - now)
2
| © 2017 by ANTID0TE All rights reserved
What is this talk about?
• between iOS 9.0 and iOS 9.1 the Zone Allocator had a bug
• it was fixed later due to refactoring of zcram()
• bug is not a security bug but influences heap layout
• might cause trouble for previously working heap-feng-shui code
3
| © 2017 by ANTID0TE All rights reserved
iOS Zone Allocator Allocations in iOS <= 6
• memory page is split into elements
• in this example allocation size 64
• every single element is used
• 64 elements per page
4
| © 2017 by ANTID0TE All rights reserved
iOS Zone Allocator Allocations in iOS 7 & 8
• Apple added meta data to end of page
• one less element (63) fits into a page
• exactly what we expect due to

the meta data at end
5
| © 2017 by ANTID0TE All rights reserved
iOS Zone Allocator Allocations in iOS 9
• Apple moved meta data to beginning of page
• block in beginning cannot be used
• but why only 62 elements?
• why is the last block still unused?
• there must be something wrong
6
| © 2017 by ANTID0TE All rights reserved
zcram() (I)
• first element positioned aligned after meta data
• following elements are added one by one
7
vm_offset_t first_element_offset;
if (zone_page_metadata_size % ZONE_ELEMENT_ALIGNMENT == 0){
first_element_offset = zone_page_metadata_size;
} else {
first_element_offset = zone_page_metadata_size + 

(ZONE_ELEMENT_ALIGNMENT - (zone_page_metadata_size % ZONE_ELEMENT_ALIGNMENT));
}
for (pos_in_page = first_element_offset; 

(newmem + pos_in_page + elem_size) < (vm_offset_t)(newmem + PAGE_SIZE); 

pos_in_page += elem_size) {
page_metadata->alloc_count++;
zone->count++; /* compensate for free_to_zone */
free_to_zone(zone, newmem + pos_in_page, FALSE);
zone->cur_size += elem_size;
}
| © 2017 by ANTID0TE All rights reserved
zcram() (II)
• checks in each iteration if end of element is still within page
• check is broken it uses < (newmem + PAGE_SIZE)
• if element ends exactly on page boundary it is considered out of bound
• must be <= (newmem + PAGE_SIZE) otherwise always loses last element
8
for (pos_in_page = first_element_offset; 

(newmem + pos_in_page + elem_size) < (vm_offset_t)(newmem + PAGE_SIZE);
pos_in_page += elem_size) {
page_metadata->alloc_count++;
zone->count++; /* compensate for free_to_zone */
free_to_zone(zone, newmem + pos_in_page, FALSE);
zone->cur_size += elem_size;
}
| © 2017 by ANTID0TE All rights reserved
iOS Zone Allocator Allocations in iOS 9 >= 9.2
• Apple refactored code - freelist order now randomized
• refactoring fixed bug
• only meta data at beginning 

not used
• 63 elements fit per page
9
| © 2017 by ANTID0TE All rights reserved
iOS Zone Allocator Allocations in iOS 10
• Apple moved meta data out of page
• once again full page used for allocations
• exactly 64 elements fit into page
10
Questions ?
www.antid0te.com
stefan@antid0te.com
© 2017 by ANTID0TE. All rights reserved

Mais conteúdo relacionado

Mais de Stefan Esser

Mais de Stefan Esser (7)

SyScan360 - Stefan Esser - OS X El Capitan sinking the S\H/IP
SyScan360 - Stefan Esser - OS X El Capitan sinking the S\H/IPSyScan360 - Stefan Esser - OS X El Capitan sinking the S\H/IP
SyScan360 - Stefan Esser - OS X El Capitan sinking the S\H/IP
 
SyScan 2015 Bonus Slides - death of the vmsize=0 dyld trick
SyScan 2015 Bonus Slides - death of the vmsize=0 dyld trickSyScan 2015 Bonus Slides - death of the vmsize=0 dyld trick
SyScan 2015 Bonus Slides - death of the vmsize=0 dyld trick
 
SyScan 2015 - iOS 678 Security - A Study in Fail
SyScan 2015 - iOS 678 Security - A Study in FailSyScan 2015 - iOS 678 Security - A Study in Fail
SyScan 2015 - iOS 678 Security - A Study in Fail
 
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and EntitlementsRuxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
Ruxcon 2014 - Stefan Esser - iOS8 Containers, Sandboxes and Entitlements
 
CanSecWest 2013 - iOS 6 Exploitation 280 Days Later
CanSecWest 2013 - iOS 6 Exploitation 280 Days LaterCanSecWest 2013 - iOS 6 Exploitation 280 Days Later
CanSecWest 2013 - iOS 6 Exploitation 280 Days Later
 
SyScan Singapore 2011 - Stefan Esser - Targeting the iOS Kernel
SyScan Singapore 2011 - Stefan Esser - Targeting the iOS KernelSyScan Singapore 2011 - Stefan Esser - Targeting the iOS Kernel
SyScan Singapore 2011 - Stefan Esser - Targeting the iOS Kernel
 
BlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
BlackHat USA 2011 - Stefan Esser - iOS Kernel ExploitationBlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
BlackHat USA 2011 - Stefan Esser - iOS Kernel Exploitation
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

WhiskeyCon 2017 - 5 Minutes of MacOS/iOS Zone Allocator Fun

  • 1. 5 Minutes with the 
 MacOS / iOS Zone Allocator WhiskeyCon Singapore, March, 2017
  • 2. | © 2017 by ANTID0TE All rights reserved Who am I? • Stefan Esser • from Germany • in Information Security since 1998 • SektionEins GmbH from (2007 - 2016) • Antid0te UG (2013 - now) 2
  • 3. | © 2017 by ANTID0TE All rights reserved What is this talk about? • between iOS 9.0 and iOS 9.1 the Zone Allocator had a bug • it was fixed later due to refactoring of zcram() • bug is not a security bug but influences heap layout • might cause trouble for previously working heap-feng-shui code 3
  • 4. | © 2017 by ANTID0TE All rights reserved iOS Zone Allocator Allocations in iOS <= 6 • memory page is split into elements • in this example allocation size 64 • every single element is used • 64 elements per page 4
  • 5. | © 2017 by ANTID0TE All rights reserved iOS Zone Allocator Allocations in iOS 7 & 8 • Apple added meta data to end of page • one less element (63) fits into a page • exactly what we expect due to
 the meta data at end 5
  • 6. | © 2017 by ANTID0TE All rights reserved iOS Zone Allocator Allocations in iOS 9 • Apple moved meta data to beginning of page • block in beginning cannot be used • but why only 62 elements? • why is the last block still unused? • there must be something wrong 6
  • 7. | © 2017 by ANTID0TE All rights reserved zcram() (I) • first element positioned aligned after meta data • following elements are added one by one 7 vm_offset_t first_element_offset; if (zone_page_metadata_size % ZONE_ELEMENT_ALIGNMENT == 0){ first_element_offset = zone_page_metadata_size; } else { first_element_offset = zone_page_metadata_size + 
 (ZONE_ELEMENT_ALIGNMENT - (zone_page_metadata_size % ZONE_ELEMENT_ALIGNMENT)); } for (pos_in_page = first_element_offset; 
 (newmem + pos_in_page + elem_size) < (vm_offset_t)(newmem + PAGE_SIZE); 
 pos_in_page += elem_size) { page_metadata->alloc_count++; zone->count++; /* compensate for free_to_zone */ free_to_zone(zone, newmem + pos_in_page, FALSE); zone->cur_size += elem_size; }
  • 8. | © 2017 by ANTID0TE All rights reserved zcram() (II) • checks in each iteration if end of element is still within page • check is broken it uses < (newmem + PAGE_SIZE) • if element ends exactly on page boundary it is considered out of bound • must be <= (newmem + PAGE_SIZE) otherwise always loses last element 8 for (pos_in_page = first_element_offset; 
 (newmem + pos_in_page + elem_size) < (vm_offset_t)(newmem + PAGE_SIZE); pos_in_page += elem_size) { page_metadata->alloc_count++; zone->count++; /* compensate for free_to_zone */ free_to_zone(zone, newmem + pos_in_page, FALSE); zone->cur_size += elem_size; }
  • 9. | © 2017 by ANTID0TE All rights reserved iOS Zone Allocator Allocations in iOS 9 >= 9.2 • Apple refactored code - freelist order now randomized • refactoring fixed bug • only meta data at beginning 
 not used • 63 elements fit per page 9
  • 10. | © 2017 by ANTID0TE All rights reserved iOS Zone Allocator Allocations in iOS 10 • Apple moved meta data out of page • once again full page used for allocations • exactly 64 elements fit into page 10