%3CLINGO-SUB%20id%3D%22lingo-sub-1796510%22%20slang%3D%22en-US%22%3EDeveloping%20secure%20coding%20in%20Azure%20Sphere%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1796510%22%20slang%3D%22en-US%22%3E%3CP%3E%22How%20do%20you%20develop%20secure%20code%3F%22%20I've%20been%20asked%20this%20a%20lot%20recently%20and%20it%20is%20time%20for%20a%20blog%20post%20as%20the%20public%20and%20various%20parts%20of%20Microsoft%20have%20gotten%20a%20glimpse%20of%20how%20much%20Azure%20Sphere%20goes%20through%20to%20hold%20to%20our%20security%20promises.%20This%20will%20not%20be%20a%20short%20blog%20post%20as%20I%20have%20a%20lot%20to%20cover.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20joined%20Microsoft%20in%20February%202019%20with%20the%20goal%20of%20improving%20the%20security%20posture%20of%20Azure%20Sphere%20and%20also%20desired%20to%20give%20back%20to%20the%20public%20community%20when%20possible.%20My%20talk%20at%20the%20Platform%20Security%20Summit%20talks%20about%20the%20hardware%20however%20the%20talk%20did%20not%20provide%20detailed%20answers%20on%20how%20to%20improve%20security%20for%20software%20development%20and%20testing.%20Azure%20Sphere's%20focus%20is%20IoT%20however%20we%20still%20give%20back%20to%20the%20open%20source%20community%20and%20want%20to%20see%20the%20software%20industry%20improve%20too%2C%20this%20blog%20post%20is%20to%20help%20reveal%20the%20efforts%20we%20go%20through%20and%20hopefully%20help%20others%20understand%20what%20it%20means%20to%20sign%20up%20saying%20you%20are%20secure.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20you%20must%20realize%20that%20there%20is%20no%20magic%20bullet%20or%20single%20solution%20to%20keep%20a%20system%20secure%2C%20there%20are%20a%20wide%20range%20of%20potential%20issues%20and%20problems%20that%20require%20solutions.%20You%20must%20also%20accept%20that%20all%20code%20must%20be%20questioned%20regardless%20of%20where%20it%20is%20from%2C%20so%20how%20does%20Azure%20Sphere%20handle%20this%3F%20We%20have%20a%20range%20of%20guidelines%20and%20rules%20that%20we%20refuse%20to%20bend%20on.%20These%20become%20our%20foundation%20when%20questions%20come%20up%20about%20allowing%20an%20exception%20or%20if%20a%20new%20feature%20has%20the%20right%20design%20by%20checking%20if%20it%20violates%20a%20rule%20we%20refuse%20to%20bend%20on.%20The%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2F7properties%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E7%20properties%3C%2FA%3E%20is%20a%20good%20starting%20point%20and%20provides%20a%20number%20of%20overarching%20requirements%2C%20this%20is%20further%20extended%20with%20internal%20requirements%20that%20we%20do%20not%20want%20to%20bend%20on%2C%20an%20example%20being%20no%20unsigned%20code%20can%20ever%20be%20allowed%20to%20execute.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20is%20your%20foundation%3F%20What%20lines%20are%20you%20willing%20to%20draw%20in%20the%20sand%20that%20can%20not%20be%20compromised%2C%20bent%2C%20or%20ignored%3F%20Our%20foundation%20of%20what%20we%20deem%20secure%20is%20always%20being%20improved%20and%20expanded%20with%20the%20following%20being%20a%20few%20examples.%20These%20are%20meant%20to%20help%20drive%20thoughts%20on%20what%20works%20on%20your%20own%20software%20and%20is%20not%20meant%20to%20be%20a%20complete%20list.%20By%20having%20these%20lines%20along%20with%20the%207%20properties%20allows%20for%20better%20security%20decisions%20as%20new%20features%20are%20added.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ENo%20unsigned%20code%20allowed%20on%20the%20platform%3C%2FLI%3E%0A%3CLI%3EWill%20delay%20or%20stop%20feature%20development%20that%20risks%20the%20security%20of%20the%20platform%3C%2FLI%3E%0A%3CLI%3EWilling%20to%20do%20an%20out-of-band%20release%20if%20a%20security%20compromise%20or%20CVE%20is%20impactful%20enough%3C%2FLI%3E%0A%3CLI%3ENetworkD%20is%20the%20only%20daemon%20allowed%20to%20have%20CAP_NET_ADMIN%20and%20CAP_NET_RAW%3C%2FLI%3E%0A%3CLI%3EAssume%20the%20application%20on%20a%20real-time%20core%20is%20compromised%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ENow%20that%20a%20base%20foundation%20is%20laid%20we%20can%20build%20on%20top%20of%20it%20to%20better%20protect%20the%20platform.%20Although%20we%20require%20all%20code%20to%20be%20signed%20that%20does%20not%20mean%20it%20is%20bug%20free%2C%20humans%20make%20mistakes%20and%20it%20is%20easy%20to%20overlook%20a%20bug.%20We%20can%20bring%20tools%20to%20the%20table%20to%20help%20remove%20both%20low%20hanging%20fruit%20and%20easily%20abusable%20bugs%2C%20in%20our%20case%20we%20use%20%3CA%20href%3D%22https%3A%2F%2Fclang.llvm.org%2Fextra%2Fclang-tidy%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eclang-tidy%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fwww.synopsys.com%2Fsoftware-integrity%2Fsecurity-testing%2Fstatic-analysis-sast.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECoverity%20Static%20Analysis%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eclang-tidy%20has%20over%20400%20checks%20that%20can%20be%20done%20as%20part%20of%20static%20code%20analysis%2C%20we%20run%20with%20over%20300%20of%20the%20checks%20enabled.%20Although%20clang-tidy%20can%20detect%20a%20lot%20of%20simpler%20bugs%20it%20does%20not%20do%20a%20good%20job%20of%20deeper%20introspection%20at%20a%20static%20level%2C%20this%20is%20where%20Coverity%20comes%20into%20play.%20Coverity%20allows%20us%20to%20pick%20up%20where%20clang-tidy%20leaves%20off%20and%20provide%20deeper%20introspection%20of%20data%20usage%20between%20functions%20along%20with%20more%20stringent%20validations%20for%20potential%20failing%20code%20paths.%20A%20good%20question%20at%20this%20point%20is%20%22how%20often%20should%20such%20tools%20be%20ran%3F%22%20We%20want%20to%20eliminate%20coding%20flaws%20quickly%2C%20so%20both%20tools%20get%20ran%20on%20every%20pull%20request%20(PR)%20to%20our%20internal%20repos%20and%20the%20tools%20must%20pass%20before%20the%20PR%20is%20allowed%20to%20complete.%20This%20requirement%20does%20impact%20build%20times%20but%20not%20as%20much%20as%20may%20be%20expected.%20Our%20base%20code%20running%20under%20Linux%20is%20approaching%20250k%20lines%20of%20total%20code%20in%20the%20repository%20across%202.4k%20files%2C%20running%20both%20tools%20adds%20roughly%208%20minutes%20to%20the%20build%20and%20is%20not%20a%20bad%20trade%20off%20for%20the%20amount%20of%20validation%20being%20done.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eclang-tidy%20and%20Coverity%20is%20not%20enough%20for%20us%2C%20it%20is%20still%20possible%20to%20mess%20up%20string%20parsing%20and%20manipulation%2C%20array%20handling%2C%20integer%20math%20and%20various%20other%20bugs.%20To%20help%20reduce%20this%20risk%20we%20heavily%20use%20C%2B%2B%20internally%20for%20our%20code%20and%20rely%20on%20objects%20for%20string%20and%20array%20handling.%20Our%20normal%20world%2C%20secure%20world%2C%20Pluton%2C%20and%20even%20our%20rom%20code%20is%20almost%20all%20C%2B%2B%20and%20we%20do%20what%20we%20can%20to%20limit%20assembly%20usage%20in%20low%20level%20parts%20of%20the%20system.%20C%2B%2B%20does%20introduce%20new%20risks%20though%2C%20object%20confusion%20through%20inheritance%20as%20an%20example.%20Part%20of%20our%20coding%20practices%20is%20that%20very%20few%20classes%20are%20allowed%20to%20inherit%20and%20this%20is%20further%20validated%20during%20the%20PR%20process%20which%20requires%20sign-off%20by%20someone%20besides%20the%20creator%20of%20the%20PR.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELarger%20projects%20require%20more%20contributors%20which%20increases%20the%20risk%20of%20insecure%20or%20buggy%20code%20being%20checked%20in%20as%20no%20single%20person%20is%20able%20to%20understand%20the%20whole%20code%20base.%20Allowing%20anyone%20to%20submit%20a%20PR%20then%20approve%20it%20themselves%20runs%20the%20risk%20of%20introducing%20bugs%20but%20having%20every%20lead%20engineer%20setup%20to%20sign%20off%20causes%20complications%20and%20bottlenecks%20when%20leads%20are%20only%20responsible%20for%20specific%20parts%20of%20the%20code%20base.%20Our%20PR%20pipeline%20has%20a%20number%20of%20automated%20scripts%2C%20one%20of%20them%20looks%20at%20a%20maintainers.txt%20file%20which%20contains%20directory%20or%20file%20paths%20along%20with%20an%20Azure%20DevOps%20(ADO)%20group%20name%20per%20line%20allowing%20an%20ADO%20group%20to%20own%20a%20specific%20directory%20and%20anything%20under%20it.%20The%20script%20auto-adds%20the%20required%20groups%20as%20reviewers%20to%20the%20PR%20forcing%20group%20sign%20off%20based%20on%20what%20files%20were%20modified%20and%20avoids%20complex%20git%20repository%20setups%20where%20a%20group%20is%20responsible%20per%20repository.%20With%20the%20growth%20of%20Azure%20Sphere's%20internal%20teams%2C%20the%20maintainers.txt%20file%20is%20re-evaluated%20every%206%20months%20by%20the%20team%20leads%20to%20make%20sure%20that%20the%20ownership%20that%20is%20specified%20for%20each%20directory%20in%20our%20repositories%20still%20makes%20sense.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20about%20when%20new%20features%20are%20developed%20and%20making%20sure%20they%20don't%20introduce%20vulnerabilities%20into%20the%20system%20from%20information%20disclosure%20to%20policies%20that%20may%20impact%20the%20system%3F%20New%20features%20have%20a%20Request%20For%20Comment%20(RFC)%20process%20where%20a%20number%20of%20requirements%20must%20be%20signed%20off%20to%20begin%20coding%2C%20one%20of%20the%20requirements%20is%20a%20security%20related%20section%20where%20potential%20risks%20are%20listed%20along%20with%20any%20tests%20and%20fuzzing%20efforts%20that%20will%20be%20done.%20Potential%20risks%20can%20be%20anything%20including%20additional%20privileges%20that%20are%20required%2C%20file%20permission%20changes%2C%20manifest%20additions%2C%20or%20a%20new%20data%20parser.%20The%20security%20team%20evaluates%20the%20design%20itself%20along%20with%20the%20identified%20risks%20and%20efforts%20to%20mitigate%20before%20signing%20off%20on%20the%20design.%20Security%20sign-off%20is%20required%20to%20implement%20the%20new%20feature%20however%20the%20validations%20do%20not%20stop%20once%20the%20RFC%20is%20approved.%20Before%20the%20feature%20is%20exposed%20to%20customers%20it%20goes%20through%20a%20second%20check%20by%20the%20security%20team%20to%20make%20sure%20that%20what%20was%20designed%20is%20what%20was%20implemented%20for%20security%20relevant%20areas%2C%20if%20the%20tests%20for%20both%20good%20and%20bad%20input%20were%20sufficient%2C%20and%20if%20fuzzing%20was%20done%20to%20a%20satisfied%20level.%20At%20this%20point%20the%20security%20team%20signs%20off%20and%20the%20feature%20is%20available%20to%20customers%20in%20a%20new%20version%20of%20the%20software.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI've%20mentioned%20fuzzing%20but%20what%20does%20that%20actually%20mean%20and%20entail%3F%20At%20it's%20core%2C%20fuzzing%20is%20simply%20any%20method%20of%20providing%20unexpected%20input%20into%20a%20piece%20of%20code%20and%20determine%20if%20the%20code%20does%20anything%20that%20is%20not%20expected.%20Depending%20on%20how%20smart%20your%20fuzzer%20is%20and%20what%20you%20are%20watching%20quickly%20determines%20what%20%22not%20expected%22%20means%20as%20this%20could%20be%20a%20range%20of%20things%20including%20crashing%20the%20software%2C%20information%20leakage%2C%20invalid%20data%20returns%2C%20excessive%20cpu%20usage%2C%20or%20causing%20the%20software%20to%20become%20unresponsive%20and%20hang%2C%20fuzzing%20for%20Azure%20Sphere%20currently%20means%20anything%20causing%20a%20crash%20or%20a%20hang%20of%20the%20system.%20Our%20platform%20is%20very%20cpu%20constrained%20and%20does%20not%20do%20well%20for%20fuzzing%20on%20the%20actual%20hardware%20however%20with%20our%20C%2B%2B%20design%20we%20are%20able%20to%20recompile%20our%20internal%20applications%20to%20x86%20allowing%20us%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgoogle%2FAFL%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAFL%3C%2FA%3E%20based%20fuzzers%20on%20different%20components%20of%20the%20system%20and%20are%20in%20the%20process%20of%20using%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fonefuzz%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EOneFuzz%3C%2FA%3E.%20At%20times%20our%20fuzzing%20efforts%20reveal%20crashes%20in%20open%20source%20components%20which%20are%20promptly%20reported%20to%20the%20appropriate%20parties%2C%20some%20times%20with%20a%20patch%20included%2C%20allowing%20us%20to%20not%20only%20improve%20our%20security%20and%20stability%20but%20also%20benefit%20the%20open%20source%20ecosystem.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFuzzing%20each%20component%20and%20validating%20it%20runs%20properly%20is%20not%20enough%2C%20we%20must%20fuzz%20and%20test%20the%20communication%20paths%20between%20applications%20and%20between%20chips.%20Fuzzing%20at%20this%20level%20requires%20a%20complete%20system%20for%20testing%20end%20to%20end%20interactions%20which%20is%20possible%20with%20QEMU%20and%20allows%20us%20to%20extend%20the%20types%20of%20fuzzing%20we%20can%20do.%20We%20not%20only%20have%20the%20ability%20to%20fuzz%20various%20parts%20of%20the%20system%20in%20end%20to%20end%20tests%20with%20AFL%2C%20but%20are%20also%20able%20to%20test%20the%20stability%20and%20repercussions%20of%20network%20related%20areas%20including%20dropped%20network%20packets%20and%20noisy%20network%20environments%20by%20altering%20what%20QEMU%20does%20with%20the%20emulated%20network%20traffic.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOur%20ability%20to%20recompile%20the%20code%20to%20run%20on%20our%20desktop%20computers%20allows%20us%20to%20use%20other%20useful%20tools%20like%20%3CA%20href%3D%22https%3A%2F%2Fclang.llvm.org%2Fdocs%2FAddressSanitizer.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAddress%20Sanitizer%3C%2FA%3E%20(ASan)%20and%20%3CA%20href%3D%22https%3A%2F%2Fvalgrind.org%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EValgrind%3C%2FA%3E.%20We%20use%20the%20gtest%20framework%20for%20testing%20individual%20parts%20of%20the%20system%20including%20stress%20testing%2C%20it%20is%20during%20these%20tests%20that%20ASan%20and%20Valgrind%20are%20deployed.%20ASan%20allows%20for%20detection%20of%20improper%20memory%20usage%20in%20dynamic%20environments%20and%20use-after-free%20bugs%20while%20Valgrind%20adds%20additional%20detection%20for%20uninitialized%20memory%20usage%2C%20reading%20and%20writing%20memory%20after%20it%20is%20freed%2C%20and%20a%20range%20of%20other%20memory%20related%20validations.%20It%20could%20be%20considered%20overkill%20to%20be%20using%20these%20many%20tools%20on%20the%20code%2C%20however%20every%20tool%20has%20both%20strengths%20and%20weaknesses%20and%20no%20single%20tool%20is%20capable%20of%20detecting%20everything.%20The%20more%20bugs%20we%20can%20eliminate%20the%20harder%20it%20is%20to%20attack%20the%20core%20system%20as%20it%20evolves.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20use%20a%20lot%20of%20external%20software%20as%20part%20of%20our%20build%20system%20and%20a%20number%20of%20open%20source%20projects%20on%20the%20actual%20hardware%2C%20all%20of%20them%20are%20susceptible%20to%20CVEs%20which%20have%20to%20be%20monitored%20and%20quickly%20handled.%20We%20use%20Yocto%20for%20our%20builds%20and%20it%20comes%20with%20a%20useful%20tool%2C%20%3CA%20href%3D%22https%3A%2F%2Fwiki.yoctoproject.org%2Fwiki%2FSecurity%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecve-check%3C%2FA%3E%2C%20that%20queries%20the%20Mitre%20CVE%20database%2C%20our%20daily%20builds%20are%20setup%20to%20run%20this%20tool%20each%20night%20and%20alert%20us%20to%20any%20new%20CVEs%20that%20impact%20not%20only%20our%20system%20but%20also%20impact%20our%20build%20infrastructure%20for%20tools%20we%20rely%20on.%20We%20need%20to%20protect%20both%20our%20end%20product%20and%20our%20build%20system%2C%20a%20weak%20build%20system%20gives%20an%20attacker%20a%20different%20target%20that%20can%20be%20far%20more%20damaging%20across%20the%20product%20if%20the%20builds%20were%20manipulated.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20bring%20to%20bear%20static%20code%20analysis%2C%20fuzzing%2C%20and%20extra%20validations%20to%20help%20with%20security%20of%20the%20system%20and%20we%20still%20bring%20even%20more%20to%20the%20table.%20The%20security%20team%20I%20run%20is%20responsible%20for%20coordinating%20red%20teams%20to%20look%20at%20our%20software%20and%20hardware.%20We%20rely%20on%20both%20internal%20and%20external%20red%20teams%20along%20with%20interacting%20and%20helping%20with%20the%20public%20bug%20bounties%20for%20Azure%20Sphere.%20As%20a%20defender%20we%20have%20to%20defend%20from%20everything%20while%20an%20attacker%20only%20needs%20a%20single%20flaw%2C%20when%20you%20are%20focused%20on%20the%20day%20to%20day%20things%20it%20is%20easy%20to%20overlook%20a%20detail%20so%20bringing%20in%20teams%20from%20outside%20of%20the%20immediate%20organization%20with%20the%20latest%20tools%20and%20techniques%20of%20attack%20brings%20a%20fresh%20set%20of%20eyes%20to%20help%20discover%20what%20was%20overlooked.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20security%20team%20for%20Azure%20Sphere%20looks%20a%20lot%20like%20a%20red%20team%2C%20we%20are%20constantly%20trying%20to%20figure%20out%20an%20answer%20to%20%22If%20I%20control%20X%20what%20can%20I%20do%20now%3F%22%20Once%20we%20have%20an%20answer%20we%20then%20evaluate%20if%20there%20is%20a%20better%20solution%20to%20harden%20the%20platform%20while%20also%20determining%20what%20can%20be%20strengthened%20or%20improved%20while%20being%20invisible%20to%20customers.%20We%20want%20a%20secure%20platform%20for%20customers%20to%20develop%20on%20without%20additional%20complexities%20hence%20the%20effort%20to%20be%20as%20invisible%20as%20possible%20for%20security%20relevant%20validations.%20This%20has%20resulted%20in%20a%20range%20of%20internal%20changes%20from%20having%20a%20common%20IPC%20server%20code%20path%20with%20simple%20validations%20before%20handing%20IPC%20data%20off%20to%20other%20parts%20of%20the%20platform%20to%20Linux%20Kernel%20modifications.%20I%20have%20the%20personal%20view%20that%20teaching%20a%20development%20team%20to%20think%20about%20security%20is%20hard%20while%20teaching%20a%20red%20team%20to%20create%20solutions%20and%20become%20developers%20is%20easier.%20This%20view%20is%20applied%20to%20the%20security%20team%20I%20run%20resulting%20in%20a%20more%20red-team%20centric%20group%20that%20is%20always%20looking%20for%20ways%20to%20break%20the%20system%20then%20helping%20create%20solutions.%20This%20type%20of%20thought%20process%20is%20what%20drove%20the%20memory%20protection%20changes%20in%20the%20kernel%2C%20the%20ptrace%20work%20that%20was%20being%20worked%20on%20when%20the%20bug%20bounty%20event%20identified%20it%20publicly%2C%20and%20even%20drives%20what%20compilation%20flags%20are%20used.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20area%20that%20people%20don't%20always%20recognize%20is%20that%20overly%20complex%20code%20can%20result%20in%20normally%20unused%20but%20still%20accessible%20code%20paths.%20Failure%20to%20remove%20code%20that%20should%20be%20unused%20not%20only%20wastes%20space%2C%20it%20is%20an%20area%20for%20bugs%20to%20lurk%20and%20can%20also%20be%20useful%20areas%20for%20an%20attacker%2C%20remember%20they%20only%20need%20to%20find%20a%20single%20opening.%20Although%20our%20platform%20space%20is%20small%20and%20we%20have%20a%20reason%20to%20limit%20our%20code%20size%20due%20to%20the%20limited%20memory%20footprint%2C%20we%20actively%20try%20to%20keep%20unused%20code%20from%20sitting%20around%20even%20in%20the%20open%20source%20libraries%20we%20use.%20We%20don't%20need%20every%20feature%20in%20the%20Linux%20Kernel%20to%20be%20turned%20on%20so%20we%20turn%20off%20as%20much%20as%20possible%20to%20remove%20risks%2C%20less%20code%20compiled%20in%20means%20less%20areas%20for%20bugs%20to%20lurk.%20We%20apply%20this%20stripping%20mentality%20to%20everything%20we%20can%20which%20is%20why%20we%20don't%20have%20a%20local%20shell%2C%20why%20we%20custom%20compile%20wolfSSL%20to%20be%20stripped%20down%20and%20smaller%2C%20and%20why%20we%20limit%20what%20is%20on%20the%20system.%20We%20want%20to%20remove%20targets%20of%20interest%20which%20also%20allows%20us%20to%20focus%20on%20what%20targets%20are%20left.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECreating%20and%20maintaining%20security%20for%20a%20platform%20is%20not%20easy%20and%20claiming%20you%20are%20secure%20often%20draws%20a%20bullseye%20on%20your%20product%20as%20hackers%20enjoy%20proving%20someone%20wrong%20about%20how%20secure%20they%20are.%20The%20effort%20required%20to%20not%20only%20design%20and%20create%20but%20maintain%20a%20secure%20product%20is%20not%20easy%2C%20is%20not%20simple%2C%20and%20is%20not%20cheap.%20Putting%20security%20first%20and%20not%20compromising%20is%20a%20very%20hard%20and%20difficult%20choice%20as%20it%20has%20direct%20impacts%20to%20how%20fast%20you%20can%20change%20and%20adapt%20for%20customers.%20This%20blog%20post%20only%20covered%20what%20we%20do%20internally%20to%20help%20write%20secure%20code%20and%20does%20not%20touch%20on%20a%20range%20of%20topics%20including%20the%20build%20acceptance%20testing%20(BVT)%20done%20in%20emulation%20and%20on%20physical%20hardware%2C%20code%20signing%20and%20validation%2C%20certificate%20validation%20and%20revocation%20for%20cloud%20or%20resource%20access%2C%20secure%20boot%2C%20or%20any%20of%20the%20physical%20hardware%20security%20designs%20that%20were%20mentioned%20during%20my%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkbfzUSOsd5M%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Etalk%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20along%20with%20Azure%20Sphere%20want%20to%20see%20a%20more%20secure%20future%2C%20security%20requires%20dedication%20and%20the%20willingness%20to%20not%20compromise%2C%20it%20must%20come%20first%20and%20not%20be%20an%20after-thought%2C%20it%20must%20be%20maintained%2C%20and%20it%20can't%20be%20delayed%20till%20later%20due%20to%20deadlines.%20This%20blog%20post%20is%20one%20of%20many%20ways%20of%20trying%20to%20give%20back%20to%20the%20public%2C%20hopefully%20it%20has%20helped%20people%20understand%20the%20effort%20it%20takes%20to%20keep%20a%20system%20secure%20and%20can%20encourage%20both%20ideas%20and%20conversations%20about%20security%20during%20product%20development%20outside%20of%20Azure%20Sphere.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJewell%20Seay%3CBR%20%2F%3EAzure%20Sphere%20Operating%20System%20Platform%20Security%20Lead%3CBR%20%2F%3EIf%20you%20do%20not%20push%20the%20limits%20then%20you%20do%20not%20know%20what%20limits%20truly%20exist%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1796510%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Annotation%202019-10-22%20124501.png%22%20style%3D%22width%3A%20956px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F228065i8E72E01081361B64%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Annotation%202019-10-22%20124501.png%22%20alt%3D%22Annotation%202019-10-22%20124501.png%22%20%2F%3E%3C%2FSPAN%3E%22How%20do%20you%20develop%20secure%20code%3F%22%20I've%20been%20asked%20this%20a%20lot%20recently%20and%20it%20is%20time%20for%20a%20blog%20post%20as%20the%20public%20and%20various%20parts%20of%20Microsoft%20have%20gotten%20a%20glimpse%20of%20how%20much%20Azure%20Sphere%20goes%20through%20to%20hold%20to%20our%20security%20promises.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1796510%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Sphere%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Sphere%20Security%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ecoding%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESecurity%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

"How do you develop secure code?" I've been asked this a lot recently and it is time for a blog post as the public and various parts of Microsoft have gotten a glimpse of how much Azure Sphere goes through to hold to our security promises. This will not be a short blog post as I have a lot to cover.

 

I joined Microsoft in February 2019 with the goal of improving the security posture of Azure Sphere and also desired to give back to the public community when possible. My talk at the Platform Security Summit talks about the hardware however the talk did not provide detailed answers on how to improve security for software development and testing. Azure Sphere's focus is IoT however we still give back to the open source community and want to see the software industry improve too, this blog post is to help reveal the efforts we go through and hopefully help others understand what it means to sign up saying you are secure.

 

First, you must realize that there is no magic bullet or single solution to keep a system secure, there are a wide range of potential issues and problems that require solutions. You must also accept that all code must be questioned regardless of where it is from, so how does Azure Sphere handle this? We have a range of guidelines and rules that we refuse to bend on. These become our foundation when questions come up about allowing an exception or if a new feature has the right design by checking if it violates a rule we refuse to bend on. The 7 properties is a good starting point and provides a number of overarching requirements, this is further extended with internal requirements that we do not want to bend on, an example being no unsigned code can ever be allowed to execute.

 

What is your foundation? What lines are you willing to draw in the sand that can not be compromised, bent, or ignored? Our foundation of what we deem secure is always being improved and expanded with the following being a few examples. These are meant to help drive thoughts on what works on your own software and is not meant to be a complete list. By having these lines along with the 7 properties allows for better security decisions as new features are added.

 

  • No unsigned code allowed on the platform
  • Will delay or stop feature development that risks the security of the platform
  • Willing to do an out-of-band release if a security compromise or CVE is impactful enough
  • NetworkD is the only daemon allowed to have CAP_NET_ADMIN and CAP_NET_RAW
  • Assume the application on a real-time core is compromised

Now that a base foundation is laid we can build on top of it to better protect the platform. Although we require all code to be signed that does not mean it is bug free, humans make mistakes and it is easy to overlook a bug. We can bring tools to the table to help remove both low hanging fruit and easily abusable bugs, in our case we use clang-tidy and Coverity Static Analysis.

 

clang-tidy has over 400 checks that can be done as part of static code analysis, we run with over 300 of the checks enabled. Although clang-tidy can detect a lot of simpler bugs it does not do a good job of deeper introspection at a static level, this is where Coverity comes into play. Coverity allows us to pick up where clang-tidy leaves off and provide deeper introspection of data usage between functions along with more stringent validations for potential failing code paths. A good question at this point is "how often should such tools be ran?" We want to eliminate coding flaws quickly, so both tools get ran on every pull request (PR) to our internal repos and the tools must pass before the PR is allowed to complete. This requirement does impact build times but not as much as may be expected. Our base code running under Linux is approaching 250k lines of total code in the repository across 2.4k files, running both tools adds roughly 8 minutes to the build and is not a bad trade off for the amount of validation being done.

 

clang-tidy and Coverity is not enough for us, it is still possible to mess up string parsing and manipulation, array handling, integer math and various other bugs. To help reduce this risk we heavily use C++ internally for our code and rely on objects for string and array handling. Our normal world, secure world, Pluton, and even our rom code is almost all C++ and we do what we can to limit assembly usage in low level parts of the system. C++ does introduce new risks though, object confusion through inheritance as an example. Part of our coding practices is that very few classes are allowed to inherit and this is further validated during the PR process which requires sign-off by someone besides the creator of the PR.

 

Larger projects require more contributors which increases the risk of insecure or buggy code being checked in as no single person is able to understand the whole code base. Allowing anyone to submit a PR then approve it themselves runs the risk of introducing bugs but having every lead engineer setup to sign off causes complications and bottlenecks when leads are only responsible for specific parts of the code base. Our PR pipeline has a number of automated scripts, one of them looks at a maintainers.txt file which contains directory or file paths along with an Azure DevOps (ADO) group name per line allowing an ADO group to own a specific directory and anything under it. The script auto-adds the required groups as reviewers to the PR forcing group sign off based on what files were modified and avoids complex git repository setups where a group is responsible per repository. With the growth of Azure Sphere's internal teams, the maintainers.txt file is re-evaluated every 6 months by the team leads to make sure that the ownership that is specified for each directory in our repositories still makes sense.

 

What about when new features are developed and making sure they don't introduce vulnerabilities into the system from information disclosure to policies that may impact the system? New features have a Request For Comment (RFC) process where a number of requirements must be signed off to begin coding, one of the requirements is a security related section where potential risks are listed along with any tests and fuzzing efforts that will be done. Potential risks can be anything including additional privileges that are required, file permission changes, manifest additions, or a new data parser. The security team evaluates the design itself along with the identified risks and efforts to mitigate before signing off on the design. Security sign-off is required to implement the new feature however the validations do not stop once the RFC is approved. Before the feature is exposed to customers it goes through a second check by the security team to make sure that what was designed is what was implemented for security relevant areas, if the tests for both good and bad input were sufficient, and if fuzzing was done to a satisfied level. At this point the security team signs off and the feature is available to customers in a new version of the software.

 

I've mentioned fuzzing but what does that actually mean and entail? At it's core, fuzzing is simply any method of providing unexpected input into a piece of code and determine if the code does anything that is not expected. Depending on how smart your fuzzer is and what you are watching quickly determines what "not expected" means as this could be a range of things including crashing the software, information leakage, invalid data returns, excessive cpu usage, or causing the software to become unresponsive and hang, fuzzing for Azure Sphere currently means anything causing a crash or a hang of the system. Our platform is very cpu constrained and does not do well for fuzzing on the actual hardware however with our C++ design we are able to recompile our internal applications to x86 allowing us to use AFL based fuzzers on different components of the system and are in the process of using OneFuzz. At times our fuzzing efforts reveal crashes in open source components which are promptly reported to the appropriate parties, some times with a patch included, allowing us to not only improve our security and stability but also benefit the open source ecosystem.

 

Fuzzing each component and validating it runs properly is not enough, we must fuzz and test the communication paths between applications and between chips. Fuzzing at this level requires a complete system for testing end to end interactions which is possible with QEMU and allows us to extend the types of fuzzing we can do. We not only have the ability to fuzz various parts of the system in end to end tests with AFL, but are also able to test the stability and repercussions of network related areas including dropped network packets and noisy network environments by altering what QEMU does with the emulated network traffic.

 

Our ability to recompile the code to run on our desktop computers allows us to use other useful tools like Address Sanitizer (ASan) and Valgrind. We use the gtest framework for testing individual parts of the system including stress testing, it is during these tests that ASan and Valgrind are deployed. ASan allows for detection of improper memory usage in dynamic environments and use-after-free bugs while Valgrind adds additional detection for uninitialized memory usage, reading and writing memory after it is freed, and a range of other memory related validations. It could be considered overkill to be using these many tools on the code, however every tool has both strengths and weaknesses and no single tool is capable of detecting everything. The more bugs we can eliminate the harder it is to attack the core system as it evolves.

 

We use a lot of external software as part of our build system and a number of open source projects on the actual hardware, all of them are susceptible to CVEs which have to be monitored and quickly handled. We use Yocto for our builds and it comes with a useful tool, cve-check, that queries the Mitre CVE database, our daily builds are setup to run this tool each night and alert us to any new CVEs that impact not only our system but also impact our build infrastructure for tools we rely on. We need to protect both our end product and our build system, a weak build system gives an attacker a different target that can be far more damaging across the product if the builds were manipulated.

 

We bring to bear static code analysis, fuzzing, and extra validations to help with security of the system and we still bring even more to the table. The security team I run is responsible for coordinating red teams to look at our software and hardware. We rely on both internal and external red teams along with interacting and helping with the public bug bounties for Azure Sphere. As a defender we have to defend from everything while an attacker only needs a single flaw, when you are focused on the day to day things it is easy to overlook a detail so bringing in teams from outside of the immediate organization with the latest tools and techniques of attack brings a fresh set of eyes to help discover what was overlooked.

 

The security team for Azure Sphere looks a lot like a red team, we are constantly trying to figure out an answer to "If I control X what can I do now?" Once we have an answer we then evaluate if there is a better solution to harden the platform while also determining what can be strengthened or improved while being invisible to customers. We want a secure platform for customers to develop on without additional complexities hence the effort to be as invisible as possible for security relevant validations. This has resulted in a range of internal changes from having a common IPC server code path with simple validations before handing IPC data off to other parts of the platform to Linux Kernel modifications. I have the personal view that teaching a development team to think about security is hard while teaching a red team to create solutions and become developers is easier. This view is applied to the security team I run resulting in a more red-team centric group that is always looking for ways to break the system then helping create solutions. This type of thought process is what drove the memory protection changes in the kernel, the ptrace work that was being worked on when the bug bounty event identified it publicly, and even drives what compilation flags are used.

 

Another area that people don't always recognize is that overly complex code can result in normally unused but still accessible code paths. Failure to remove code that should be unused not only wastes space, it is an area for bugs to lurk and can also be useful areas for an attacker, remember they only need to find a single opening. Although our platform space is small and we have a reason to limit our code size due to the limited memory footprint, we actively try to keep unused code from sitting around even in the open source libraries we use. We don't need every feature in the Linux Kernel to be turned on so we turn off as much as possible to remove risks, less code compiled in means less areas for bugs to lurk. We apply this stripping mentality to everything we can which is why we don't have a local shell, why we custom compile wolfSSL to be stripped down and smaller, and why we limit what is on the system. We want to remove targets of interest which also allows us to focus on what targets are left.

 

Creating and maintaining security for a platform is not easy and claiming you are secure often draws a bullseye on your product as hackers enjoy proving someone wrong about how secure they are. The effort required to not only design and create but maintain a secure product is not easy, is not simple, and is not cheap. Putting security first and not compromising is a very hard and difficult choice as it has direct impacts to how fast you can change and adapt for customers. This blog post only covered what we do internally to help write secure code and does not touch on a range of topics including the build acceptance testing (BVT) done in emulation and on physical hardware, code signing and validation, certificate validation and revocation for cloud or resource access, secure boot, or any of the physical hardware security designs that were mentioned during my talk.

 

I along with Azure Sphere want to see a more secure future, security requires dedication and the willingness to not compromise, it must come first and not be an after-thought, it must be maintained, and it can't be delayed till later due to deadlines. This blog post is one of many ways of trying to give back to the public, hopefully it has helped people understand the effort it takes to keep a system secure and can encourage both ideas and conversations about security during product development outside of Azure Sphere.

 

Jewell Seay
Azure Sphere Operating System Platform Security Lead
If you do not push the limits then you do not know what limits truly exist