from collision to exploitation: unleashing use-after-free...

25
From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities in Linux Kernel Wen Xu, Juanru Li, Junliang Shu, Wenbo Yang, Tianyi Xie, Yuanyuan Zhang, Dawu Gu Group of Software Security In Progress Lab of Cryptology and Computer Security Shanghai Jiao Tong University CCS 2015 1 GoSSIP@LoCCS Shanghai Jiao Tong University

Upload: others

Post on 25-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

FromCollisionToExploitation:UnleashingUse-After-Free

VulnerabilitiesinLinuxKernelWenXu,Juanru Li,Junliang Shu,Wenbo Yang,

Tianyi Xie,Yuanyuan Zhang,Dawu GuGroupofSoftwareSecurityInProgressLabofCryptologyandComputerSecurity

ShanghaiJiaoTongUniversity

CCS2015 1GoSSIP@LoCCSShanghaiJiaoTongUniversity

Page 2: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Introduction

• Linuxkernelbecomesawelcomedtarget– Acompletecontrolofthesystem– Lessprotectionandmitigationschemes

• Exploitingkernelbugsisnon-trivial– Fewdocumentedtechniques– Unpredictablememorylayout

• Ourgoalistofindagenericwaytoexploitinguse-after-freebugsinLinuxkernel.

CCS2015 2

Page 3: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Use-after-freeinLinuxkernel

CCS2015 3

• Option2istofree anobjectwithoutcleaningthepointer– obj[index]isso-called“adanglingpointer”sinceitpointstoafreedspace

• Option3istouse anobjectwithoutcheckingwhetherthepointerisvalid– Here“use”representsinvokingafunctionpointerbeingstoredintheobject

Page 4: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Exploitinguse-after-freebugs

• Ourgoaltoisre-occupythevulnerablefreedobjectwithcontrollable data.– Thefree memoryistobereused,whichprovidesanopportunityforattackerstore-controlthefreedspace.

– Controllabledatacontributestounintendedcontrol-flowhijackingordatacorruptioninlaterusing.

CCS2015 4

Page 5: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Challenges• Stability:The“hole”shouldbere-occupiedbyour

candidates.– Hundredsofscheduledtasksallaffectkernelallocators.

• Separation:The“hole”shouldbere-occupiedbypropercandidates.– Differenttypesofkernelobjectscannotbestoredinthesame

memoryregionduetoSLAB/SLUB.• Data-control:The“hole”shouldbefilledwithmeaningful

content.– Thecontentofkernelobjectsareusuallynotfullycontrolledby

users.• Universality:Onestrategyregardlessoftypesofvulnerable

objects.

CCS2015 5

Page 6: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Insight:MemoryCollision

• Kernelrecyclesfreememoryforfutureuse.–Memorylimitation– Performancerequirement– Reductionoftheentropyofmemorylayout

• Memorycollisionattackstrategy– Tousepropercandidatesandletthembechosenbythekerneltooccupytherecentlyfreedspace• Infact,tocollidewiththefreed“hole”

– Probabilisticmodelwithhighsuccessrate

CCS2015 6

Page 7: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Overview

• Object-basedmemorycollisionattack– Candidate:kernelbuffersallocatedbykernelallocators

• Physmap-basedmemorycollisionattack– Candidate:physmap– Generic,stableandreliable

CCS2015 7

Page 8: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Overview

CCS2015 8

Page 9: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Object-basedAttack

• Intuitivestrategy– Tousekernelobjectsoverwritingkernelobjects

• KernelobjectsarestoredinvariouskindsofSLABcaches.– Differentcachesarefordifferentobjectswhichimpliesanaturalseparation.

– HowtoinsertanobjectoftypeAintothecachesstoringvulnerableobjectsoftypeB?

CCS2015 9

Page 10: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Object-basedAttack

CCS2015 10

Page 11: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Object-basedAttack#1CollisionsbetweenObjectsoftheSameSize

• Savior:NewlyadoptedSLUBallocators– Putobjectsofthesamesizeintoonecacheforperformancepromotion.

• Candidate:kmalloc()buffers– Usedbykerneltostoretemporarydatacommonly– Easytocreatebyusers:sendmmsg()• Controllablesize:Lengthofcontrolmessage• Controllablecontent:Dataofcontrolmessage• Allpassedfromuserspace

CCS2015 11

Page 12: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Object-basedAttack#1CollisionsbetweenObjectsoftheSameSize

CCS2015 12

• Noticethatthelengthofthemessagebuffershouldbethesameasthesizeofthevulnerableobject(512).

• Limitation:– kmalloc()allocatesspaceofaroundedsize like32,48,64,128,256,512,1024…

– Whatifthevulnerableobjecthasasizeof576?• 512<576<1024

Page 13: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Object-basedAttack#2CollisionsbetweenObjectsofDifferentSizes

• Ifalltheobjectsinacachearefreed,thewholespaceofthecacheisgoingtoberecycledbythekernel.– Isthespacedefinitely tobere-usedforacachestoringtheobjectsoftheoriginaltype?No.

– Kernelnevercaresaboutthehistoryoffreememory.Memoryisjustmemory.

– Chancesarethatthespaceisgoingtobeusedforanewcachestoringobjectsofadifferenttype.

CCS2015 13

Page 14: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Object-basedAttack#2CollisionsbetweenObjectsofDifferentSizes

• Theattackcoderemainstobethesame.– Nocareaboutthesizeofourmessagebuffer– Pickakmalloc()sizeyouprefer

• Discussions– Theoretically,collisionsalwayshappeneventually.– Practically,suchakindofblindstrategysuffersalowsuccessrate.

– Usuallyduetotheresourcelimitation,oneusercannotowntoomanykmalloc()buffersinthekernel.

CCS2015 14

Page 15: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Physmap-basedAttack

• Getridofrestrictionsprovidedbythekernelallocators.– Again,memoryisjustmemory.Thekernelneverclaimsthatthememoryonceforkernelobjectsisalwaysforkernelobjects.

–Wechooseacandidateknownasphysmap toachieveagenericandstableattackagainstuse-after-freevulnerabilitiesinLinuxkernel.

CCS2015 15

Page 16: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Physmap-basedAttack

CCS2015 16

Physmap, thedirect-mappedmemory,ismemoryinthekernelspacewhichwoulddirectlymapthememoryintheuserspaceintothekernelspace.

Page 17: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Physmap-basedAttack

• AnEXCELLENTchoice– Easycreation:iterativelymmap()intheuserspace– Data-control:fullycontrolledbyattackersforsure– Largesize:

• Physmap filledwithourcraftedpayloadgrowsinthekernelbyoccupyingfreekernelspace.

CCS2015 17Table[1]fromret2dir:RethinkingKernelIsolation(USENIX14’)

Page 18: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Physmap-basedAttack

CCS2015 18

• Anintuitivestrategyistocreatealargeamountofvulnerableobjectsandfreeallofthem,thendothekernelsprayingbyphysmapandhopethecollisionhappens.

• Amorereliableapproach?

Page 19: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Physmap-basedAttack• Wesprayvulnerableobjectsingroups,foreachgroup:– ConsideringNobjectsasvulnerableones,wewilllatertriggertheUAFvulnerabilityonthem.

– ConsideringM(M>>N)objectsaspaddingones,wewilljustreleasetheminanormalway.

• Result:• (1)Largepiecesoffreedmemoryiswaitingforphysmap withpayloadtooccupy.

• (2)Wehavevulnerablefreedobjectsscatteralloverthekernelspace.

• Thesesharplyincreasethereliabilityofsuchaprobabilisticattack.

CCS2015 19

Page 20: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Physmap-basedAttack

CCS2015 20

• Inpractical,wediscoverthatuserscangetcertaindatainsidemanykernelobjectsbyspecificsyscalls.

• Thatcouldhelptoinformattackersthatthecollisionshavealreadyhappenedandthesprayingshouldbestopped.– Further increasethereliability

Page 21: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

SecurityEffectiveness• Physmap-basedattacktotallyavoidstheseparation

providedbythekernelallocatorsandachievesoverwriting.• Physmap originatesfrommmap()areainuserspace,thusit

isfullyunderthecontrolofattackers.• Physmap iseffectiveregardlessofwhattypeandsizeofthe

vulnerableobjectwhichhasause-after-freevulnerability.• Certainsprayingtricksandpotentialapproachestoleaking

informationhelpstoincreasetheprobabilitythatmemorycollisionshappen.

• Physmap-basedattackleveragestheinherentworkingmechanismofthekernel,whichcannotbemitigatedeasily.

CCS2015 21

Page 22: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Evaluation

CCS2015 22

• Hereistheperformanceofalltheseattackstargetingonthecustomvulnerablekernelmodule.

• Infact,theattackperformsworseon64bitLinuxplatform.Andalsobothphysmap-basedattackandobject-basedattack#1haveahighsuccessrate.

Page 23: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Evaluation

CCS2015 23

• WeachieveareliableuniversalrootsolutionondiverseAndroiddevicesbyleverageCVE-2015-3636,atypicaluse-after-freevulnerabilitiesinLinuxkernelcreditedtotheauthorbasedonphysmap-basedattack.

• Thatimpliesourattackisappliedbothonx86/x86_64andARMarchitectures.

Page 24: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Conclusion

• Weproposeanoval attacktechniquestounleashuse-after-freevulnerabilitiesinLinuxkernelwhichfeaturesreliabilityanduniversality.

• Countermeasures– Toimposerestrictionsonavailablememoryresourcesofaparticularuser.

– Tomakeisolationsamongmemoryofdifferentusages.

CCS2015 24

Page 25: From Collision To Exploitation: Unleashing Use-After-Free ...wen/assets/papers/xu:collision-slides.pdf · From Collision To Exploitation: Unleashing Use-After-Free Vulnerabilities

Thankyou!Q&A

CCS2015 25GoSSIP@LoCCSShanghaiJiaoTongUniversity