LectureEmbeddedSystemSecurityTrustedExecutionEnvironmentsIntelSGXProf.Dr.-Ing.Ahmad-RezaSadeghiSystemSecurityLabTechnischeUniversitätDarmstadt(CASED)GermanySummerTerm20141SYSTEMSECURITYLABSlideNr.2,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXSecuritycriticalcodeisolatedinenclaveOnlyCPUistrustedTransparentmemoryencryption18newinstructionsEnclavescannotharmthesystemOnlyunprivilegedcode(CPUring3)MemoryprotectionDesignedforMulti-CoresystemsMulti-threadedexecutionofenclavesParallelexecutionofenclavesanduntrustedcodeEnclavesareinterruptibleProgrammingReferenceavailableIntel®SoftwareGuardExtensions(SGX)APP2HardwareAPP1EnclaveSecurityServiceOperatingSystemCPUSGXTrustedUntrusted[McKeenetal,Hoekstraetal.,Anatietal.,HASP’13]SYSTEMSECURITYLABSlideNr.3,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXEnclavesareisolatedmemoryregionsofcodeanddataOnepartofphysicalmemory(RAM)isreservedforenclavesItiscalledEnclavePageCache(EPC)EPCmemoryisencryptedinthemainmemory(RAM)TrustedhardwareconsistsoftheCPU-DieonlyEPCismanagedbyOS/VMMSGXEnclavesRAM:RandomAccessMemoryOS:OperatingSystemVMM:VirtualMachineMonitor(alsoknownasHypervisor)SYSTEMSECURITYLABSlideNr.4,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGX18Instruction13SupervisorInstructions5UserInstructions13DataStructures8datastructuresassociatedtoacertainenclave3datastructuresassociatedtocertainmemorypage(s)2datastructuresassociatedtooverallresourcemanagementSGXInstructionsandDataStructuresSYSTEMSECURITYLABSlideNr.5,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXSupervisorInstructionDescriptionUserInstructionDescriptionENCLS[EADD]AddapageENCLU[EENTER]EnteranEnclaveENCLS[EBLOCK]BlockanEPCpageENCLU[EEXIT]ExitanEnclaveENCLS[ECREATE]CreateanenclaveENCLU[EGETKEY]CreateacryptographickeyENCLS[EDBGRD]ReaddatabydebuggerENCLU[EREPORT]CreateacryptographicreportENCLS[EDBGWR]WritedatabydebuggerENCLU[ERESUME]Re-enteranEnclaveENCLS[EEXTEND]ExtendEPCpagemeasurementENCLS[EINIT]InitializeanenclaveENCLS[ELDB]LoadanEPCpageasblockedENCLS[ELDU]LoadanEPCpageasunblockedENCLS[EPA]AddversionarrayENCLS[EREMOVE]RemoveapagefromEPCENCLS[ETRACK]ActivateEBLOCKchecksENCLS[EWB]Writeback/invalidateanEPCpageSGXInstructionsSYSTEMSECURITYLABSlideNr.6,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXSGXEnclaveControlStructure(SECS)ThreadControlStructure(TCS)StateSaveArea(SSA)PageInformation(PAGEINFO)SecurityInformation(SECINFO)PagingCryptoMetaData(PCMD)EnclaveSignatureStructure(SIGSTRUCT)EINTTokenStructure(EINITTOKEN)Report(REPORT)ReportTargetInfo(TARGETINFO)KeyRequest(KEYREQUEST)VersionArray(VA)EnclavePageCacheMap(EPCM)SGXDataStructuresSYSTEMSECURITYLABSlideNr.7,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXSGXEnclaveControlStructure(SECS)RepresentsoneenclaveContains,forinstance,Hash,ID,sizeetc.ThreadControlStructure(TCS)EachexecutingthreadintheenclaveisassociatedwithaThreadControlStructureContains,forinstance,Entrypoint,pointertoSSAStateSaveArea(SSA)WhenanAEXoccurswhilerunninginanenclave,thearchitecturalstateissavedinthethread’sSSASGXDataStructuresDetailsAEX:AsynchronousEnclaveExitSYSTEMSECURITYLABSlideNr.8,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXPageInformation(PAGEINFO)PAGEINFOisanarchitecturaldatastructurethatisusedasaparametertotheEPC-managementinstructionsLinearAddressEffectiveaddressofthepage(akavirtualaddress)SECINFOSECSSecurityInformation(SECINFO)TheSECINFOdatastructureholdsmeta-dataaboutanenclavepageRead/Write/ExecutePagetype(SECS,TCS,normalpageorVA)SGXDataStructuresDetailsSYSTEMSECURITYLABSlideNr.9,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXPagingCryptoMetaData(PCMD)ThePCMDstructureisusedtokeeptrackofcryptometa-dataassociatedwithapaged-outpage.CombinedwithPAGEINFO,itprovidesenoughinformationfortheprocessortoverify,decrypt,andreloadapaged-outEPCpage.EWBwritesout(thereservedfieldand)MACvalues.ELDB/UreadsthefieldsandcheckstheMAC.ContainsEnclaveID,SECINFOandMACSGXDataStructuresDetailsMAC:MessageAuthenticationCodeSYSTEMSECURITYLABSlideNr.10,LectureEmbeddedSystemSecurity,SS2014A.-R.Sadeghi©TUDarmstadt,2007-2014TrustedExecutionEnvironments/IntelSGXVersionArray(VA)InordertosecurelystoretheversionsofevictedEPCpages,SGXdefinesaspecialEPCpagetypecalledaVersionArray(VA).EachVApagecontains512slots,eachofwhichcancontainan8-byteversionnumberforapageevictedfromtheEPC.WhenanEPCpageisevicted,softwarechoosesanemptyslotinaVApage;thisslotreceivestheuniqueversionnumberofthepagebeingevicted.WhentheEPCpageisreloaded,aVAslotmustholdtheversionofthepage.Ifthepageissuccessfullyreloaded,the