Penetration Test Report (NCCGroup): NCC Group Zephyr MCUboot Research Report 2020 05 26 v1.0

Zephyr and MCUboot Security Analysis
NCC Group Research Report
May 23, 2020 – Version 1.0
Preparedby
IlyaZhuravlev
JeremyBoone
©2020–NCCGroup
PreparedbyNCCGroupSecurityServices,Inc. Portionsofthisdocumentandthetemplatesusedinits
productionarethepropertyofNCCGroupandcannotbecopied(infullorinpart)withoutNCCGroup’s
permission.
Whileprecautionshavebeentakeninthepreparationofthisdocument,NCCGroupthepublisher,and
theauthor(s)assumenoresponsibilityforerrors,omissions,orfordamagesresultingfromtheuseof
the information contained herein. Use of NCC Group’s services does not guarantee the security of a
system,orthatcomputerintrusionswillnotoccur.
Introduction
Over the years, NCC Group has audited countless embedded devices for our customers. Through these security
assessments, we have observed that IoT devices are typically built using a hodgepodge of chipset vendor board
supportpackages(BSP),bootloaders,SDKs,andanestablishedRealTimeOperatingSystem(RTOS)suchasMbedor
FreeRTOS.However,wehaverecentlybeguntofieldquestionsfromourcustomerswhoseekouropinionregarding
whethertheZephyrRTOS1andMCUbootbootloader2aresuitablefortheirneeds.
NCCGroupdecidedtoundertakeanindependentresearcheffortinordertoanalyzethesecuritypostureofZephyr
andMCUboot. Theresultsofouranalysis,includingdiscoveredvulnerabilities,arecontainedinthisresearchreport.
Background
Zephyr is an RTOS for microcontrollers and is specifically designed for applications in IoT—the types of resource-
constrainedembeddeddeviceswhereLinuxissimply“toobig”. TheZephyrprojectissponsoredbytheLinuxFounda-
tion3andrecentlyhasbeenreceivingalotofcoverage4atindustryevents. Furthermore,althoughZephyrisgoverned
by a vendor-neutral steering committee,5 it benefits from the strong support of numerous silicon vendors such as
Intel,NXP,NordicSemiconductor,andTexasInstruments,whoareaddingZephyrsupport6fortheirdevelopmentkits
inanattempttolureIoTvendorsandOEMstotheirhardwareplatforms.
TheZephyrRTOSappearstobeamatureopensourceprojectthatofferssupportforlongtermstable(LTS)releases—
a key feature that is desired by many of our customers. Zephyr is also extremely fast moving7,8 with a 3-month
release cycle and approximately 2000 commits per release. It also supports a wide variety of chipset architectures
andpopulardevelopmentkits,9includingbroadsupportfortheARMCortex-Mplatformandsomesupportforselect
x86, ARC,XTENSA,andRISC-Vplatforms. TheEclipseIoTDeveloperSurvey201910 showsthatZephyrcurrentlyhas
approximately3%oftheRTOSmarketshareforIoT,whichisaconsiderableachievementgiventherelativelyyoung
ageofZephyr.
MCUbootisanopensourcehardware-independentbootloader. ItisseenasacompanionprojecttoZephyr,asmany
of Zephyr’s supported platforms are also supported by MCUboot. The project’s stated goal is to define a common
systemflashlayoutandtoprovideasecurebootloaderthatenableseasysoftwareupgrades.
ZephyrandMCUbootbothappeartobegainingmomentumandbenefitfrombroadindustrysupport. Webelievethat
thefragmentationoftheembeddedOSmarketmaybegintoconvergeasIoTvendorsseekflexibilitytomigratefrom
onemicrocontrollertoanotherwithoutrequiringasignificantsoftwarerewrite. ZephyrandMCUbootbothappearto
offerthatlevelofflexibility.
1TheZephyrProject
2TheMCUbootproject
3TheLinuxFoundationAnnouncesProjecttoBuildReal-TimeOperatingSystemforInternetofThingsDevices
4ZephyrProjecttechnicaltalksvideoplaylist
5ZephyrProject300ContributorsAnnouncement
6TheNordicSemiconductorConnectSDKusesZephyr
7ZephyristhemostactiveprojectaccordingtotheFLOSSFoundationdashboard
8ZephyrOS:TowardsFunctionallySafeOpenSourceRTOS(slides8,27,28)
9ZephyrProjectDocumentation-SupportedBoards
10AblogpostanalyzingtheresultsoftheEclipseIoTDeveloperSurvey2019
2 | ZephyrandMCUbootSecurityResearch NCCGroup
Motivation
Acommonpitfallwithhardware-independentoperatingsystemsandbootloadersisrelatedtowhatweatNCCGroup
sometimesrefertoas“lowestcommondenominator”threatmodeling.
Whenthreatmodeling,itisessentialtodefinethelistofcriticalassetsandtheirrequiredsecuritypropertiessuchas
confidentiality,integrity,availability,authenticity,privacy,safety,oranti-replay. However,hardwaresupportisneeded
inordertomakestrongguaranteesaroundthesesecurityrequirements. Forexample, thehardwaremustsupport
marking regions of flash as immutable so that the bootloader can be write-protected. This act of protecting the
bootloader forms the hardware-based root of trust, and prevents a compromised application or physical attacker
fromtamperingwiththebootloader. Similarly,otherregionsofflashmemorymustberead-protected11toensurethat
secretkeyscannotbeeasilyextracted. Additionally,theproductmustcontainsomenotionofsecurebootwhereinthe
bootloaderwillcryptographicallyverifytheapplicationimage. Withoutthesesortsofhardware-backedguarantees,it
becomesimpossibletobuildasecureoperatingsystemthatiscapableofupholdingtherequirementsoutlinedinthe
threatmodel.
Ultimately,thesehardware-specificdesignconsiderationstendtobedifficulttosolveinahardware-independentway.
Therefore embedded operating systems will sometimes attempt to maximize their portability by leaving the heavy
liftingtothedeviceOEM,whoisexpectedimplementthehardwaresecuritysupportthemselves,oftenrequiringspecial
stepsduringmanufacturing. ThiscanbefurtherexacerbatediftheOSandbootloaderdonotcarefullydescribethese
gaps in their threat model documentation, or do not provide an easy path towardssolving these hardware-specific
problems.
Finally, embedded operating systems sometimes assume a threat model that is incongruent with the risk profile of
theirdeviceOEMcustomers. Forexample,IoTdevicesmaybeportable(orwearable12)ormaybedeployedinremote
unmonitoredlocationssuchasagriculturalcropsensors.13 Thesescenariosrequirethatthethreatmodelincludesthe
possibilitythatanadversarymayhavephysicalaccesstothedeviceintheeventthatitislostorstolen. NCCGroup
believesthatZephyrandMCUboot(aswithanyotherRTOSorbootloader), mustdefineathreatmodelthatmakes
strictsecurityguaranteesthatisabletosatisfyavarietyofcustomerriskprofilesandattackscenarios.
The Zephyr Project has published an example threat model for an IoT sensor device.14 Although it appears to be
sufficientforasimplisticIoTproduct, itfailstoaccountforthewidevarietyofproductsandconfigurationsinwhich
theZephyrRTOScouldbedeployed. ThissinglehypotheticalIoTdevicedoesnotrepresentthemanypermutationsof
possibleattacksurfaces,threatactors,orassetsthatarepresentinreal-worldIoTdevicedeployments. Ontheother
hand,thethreatmodelandsecuredesigngoalsforusermodethreads15appeartobeverywelldocumented.
TheobjectiveofNCCGroup’sindependentsecurityresearchprojectwastoinspectZephyr’soverallsecurityposture,
andtoacquireadeeperunderstandingoftheRTOSsothatweareabletoprovidebetterguidancetoourcustomers.
NCCGroupalsobrieflyreviewedMCUboot,todeterminewhetheritssecurebootmechanismwasrobust. Theremain-
derofthisreportdescribesthescopeofperformedworkandtheresultsoftheresearch.
11NCCGrouppaper“MicrocontrollerReadbackProtection:BypassesandMitigations”
12AZephyr-basedhearingaidbyOticon
13NCCGrouppaper“CyberSecurityinUKAgriculture”
14ZephyrProjectDocumentation-SensorDeviceThreatModel
15ZephyrProjectDocumentation-UserMode-ThreatModel
3 | ZephyrandMCUbootSecurityResearch NCCGroup
Research Summary
Synopsis
In the early months of 2020, NCC Group undertook a research project whose purpose was to evaluate the overall
securitypostureoftheZephyrRTOSandtheMCUbootbootloaderinordertodeterminewhethertheirsecurityclaims
wereaccurate,andwhetherthetwoprojectsexposeanysignificantthreatmodelinggapsthatcouldposeariskfora
typicalIoTdevice.
TheresearcheffortsutilizedaFreedomKinetisK6416developmentboard,mainlyforthepurposeofdevelopingproof-
of-conceptexploits. Additionally,Zephyr’snativePOSIX17functionalitywasleveragedinordertoenableNCCGroupto
runZephyronahostOSsothatitcouldbemoreeasilyfuzzedusingHonggfuzz18andAddressSanitizer.19
Throughouttheresearchproject, NCCGroupreviewedZephyratGitrevisionb413223a66(v2.1.0), andMCUbootat
revision7fea846(v1.3.1).
ResearchPriorities
OurresearcheffortscoveredvariousaspectsofZephyrandMCUbo