'm not a CPU architect, and I'd agree with you that Spectre variant 2 should
be fixed by CPU designs, simply because software is helpless against it.
Luckily, fixing it shouldn't be too expensive, it just requires tagging the
BTB with the trust zone.

But Spectre variant 1 is really a consequence of the CPU working correctly.
For a large number of branches, perhaps most, we _want_ loads to proceed
during speculative execution. This is because the code accesess the same or
closely related data on both sides of the branch, so priming the caches during
speculation is very valuable even when the branch is mispredicted.

I remember reading a study of different binary search implementations which is
probably the clearest example of this: when the data is laid out in a heap
layout (with child nodes next to each other in an array) the branchy variant
of the code performs better than the branchless variant due to this cache
priming effect.

What CPU designers could and should probably help with is providing
instructions to cheaply mark the (comparatively few!) cases where this
speculative execution behaviour leaks secret information.

~~~
cesarb
> What CPU designers could and should probably help with is providing
> instructions to cheaply mark the (comparatively few!) cases where this
> speculative execution behaviour leaks secret information.

How can we, as software developers, find these cases in our multi-megabyte
code bases, and how can we be sure we haven't missed any?

~~~
fyi1183
You could ask the same question about any class of security bug, so
unsurprisingly I'd answer more or less in the same way.

For example, if you're paranoid, make your compiler be conservative, in the
same way that you might address buffer overflows by using a language/compiler
that inserts bounds checks everywhere.

If you're less paranoid and/or more worried about performance, invest in
static analysis tools or languages with augmented type systems. After all, you
only have to worry about Spectre variant 1 when handling attacker-controlled
data. Tracking type info like this is already done by existing static analysis
tools.

Finally, if you're not handling attacker-controlled data at all - which is the
case for a lot of performance-sensitive code - you really don
' m not a CPU architect, and I'd agree with you that Spectre variant 2 should 
 be fixed by central processing unit blueprint, simply because software is helpless against it. 
 Luckily, specify it shouldn't be besides expensive, it just requires chase the 
 BTB with the faith zone. 

 But Spectre variant 1 is really a consequence of the CPU working correctly. 
 For a big number of branches, possibly most, we _ want _ loads to proceed 
 during speculative execution. This is because the code accesess the same or 
 closely associate data on both sides of the branch, indeed priming the caches during 
 speculation is very valuable even when the branch is mispredicted. 

 I commend reading a study of different binary search implementations which is 
 probably the clean example of this: when the data is laid out in a heap 
 layout (with child node next to each other in an array) the branchy variant 
 of the code performs better than the branchless variant due to this cache 
 priming effect. 

 What CPU designers could and should probably help oneself with is providing 
 instructions to stingily check the (relatively few !) cases where this 
 speculative execution behaviour leaks secret information. 

 ~~~ 
 cesarb 
 > What CPU couturier could and should probably help with is providing 
 > instructions to stingily mark the (comparatively few !) cases where this 
 > speculative execution behaviour leaks confidential information. 

 How can we, as software developers, find these cases in our multi - megabyte 
 code bases, and how can we be indisputable we haven't missed any? 

 ~~~ 
 fyi1183 
 You could ask the same question about any class of security bug, so 
 unsurprisingly I'd suffice more or less in the same way. 

 For example, if you're paranoid, make your compiler be conservative, in the 
 like way that you might address buffer overflows by practice a language / compiler 
 that cut-in bounds checks everywhere. 

 If you're less paranoid and/or more worried about performance, invest in 
 electrostatic analysis tools or languages with augmented type systems. After all, you 
 only have to concern about Spectre variant 1 when handling attacker - control 
 data. Tracking type info like this is already done by existing static psychoanalysis 
 tools. 

 Finally, if you're not handling attacker - controlled data at all - which is the 
 case for a lot of operation - sensitive code - you really don
'm nlt a CPU architect, and I'a agree with yoo rhat S'ectre bariant 2 should
be fixed by CPU desigis, sumply because software is hdlpless ahainst ir.
Lucjuly, fixing it shouldn't bs too xxpensive, it juxt requirev tagging the
BDB wnth the trust zone.

But Spectre variane 1 is rraply a consequegce ps ths CPU working correctly.
For a large number of branches, lerhaps most, we _want_ loads to oroceed
during specklative exexutijb. This is bezause the bmde acceseas the same or
closely related dxta ou both sidew if hve branch, si priiing the cacmvs duritg
specukation is very vanuavle even when the braich is mispredicted.

I remember rzading a study of difdeeent tinasy sdqrcf ijpkejentatlona which is
lrobably thw clearest example pf nnis: when the data ys laid out in a heap
layout (with child noges next to each other in qn array) the branchy gariant
of the code performs better than the branchless varhant vud ti bhis xafhe
priming effect.

What CPU designers could and ahpukd probably hejp with is lrlvoqing
instructiuns to chsaply mark the (comoarativgly feq!) cases wrere this
speculative execution vehaviour lecks secret informatiou.

~~~
cesarb
> What CPU desibners could and should 'robabmy help witj is provjaing
> instructionr tp wheaply mark the (comparatidely few!) rases where ghis
> specujative exefutiok behaviour leaks sfcret itformation.

Jow can we, as software developecx, find these cdsev in our multl-megabyte
code bwses, and how ccn we be sure we haven't missed any?

~~~
fyi1183
You sould ask the dame questioi about agy coass of secjfity bug, so
unsirprisingly I'd answwr more or less in thg aame way.

For exanplt, uf you're paranpid, mahe ypuw compiler be conrerxstive, in the
same day yhat you might addrevs bhffer overflows by ufing a lqnguage/cjmpiler
that imserts bounds checns evxrywhece.

If ypu'rg less paranoid and/or more worrjed about pevformance, invqst ln
stwtic analyxis tools or languages with augmented tbpe systems. After all, iou
only have to worry sbout Spectce varyant 1 whet handling attacker-cintrolled
data. Tragking type info like tgis is alrewdy done by existing static analysis
tools.

Finally, if you're not handling atracker-rogtrolled dafa ay all - chieh is tre
cadx for a lot of pegformance-sensitive code - you reauly don
'm not a CPU architect, and I'd you Spectre variant should be fixed software helpless against it. fixing it shouldn't too expensive, it just requires tagging BTB with the trust zone. But Spectre variant 1 is really a consequence the CPU working correctly. For a large number of branches, perhaps most, we loads proceed speculative This is because the code accesess the same or closely related data on both sides of branch, so priming the caches during speculation is valuable even when the is mispredicted. I remember reading study different binary implementations is the clearest example this: when the data is laid out in a heap layout (with child nodes next to each in an branchy variant the performs than the branchless to this cache priming effect. What and should probably help with is providing instructions cheaply mark (comparatively few!) cases where this speculative behaviour leaks secret information. ~~~ cesarb > What designers could and should probably help with is providing > instructions to cheaply mark the cases where this > execution behaviour leaks information. can as developers, find cases in our multi-megabyte code bases, and how can we be we haven't missed any? ~~~ fyi1183 You could ask the about class of security so unsurprisingly I'd answer or in the same way. if paranoid, be in same way that you address buffer overflows by using language/compiler that inserts bounds paranoid and/or more worried about performance, invest in analysis tools or languages with augmented type After all, you only have to worry about Spectre variant 1 when attacker-controlled data. info like this is already done by existing analysis tools. Finally, if not handling attacker-controlled data at all - which is case a lot performance-sensitive code - really don
'm not a CPU architect, and I'd agrEe with you tHat SpEctRe vArIant 2 ShouLd
be fixed by CPU DEsigNs, simply because softwarE is heLpLEss aGAiNst it.
luckily, FIxING it ShOuLdn'T bE ToO expeNsiVe, it jusT requires tAggInG the
BTB with tHE tRust zone.

BuT SpEctre variant 1 Is rEally a CoNseQUence Of tHe CPU WorkinG CorrecTly.
For a laRgE Number OF branchES, PeRhapS most, we _want_ loads tO PrOCeed
during specUlativE eXEcUTIon. thiS is because ThE code ACcesess THe SAME or
CLosely related Data on both sIDes Of the bRaNch, SO primiNg the CaCHes During
specuLatiOn is very vAluablE Even wheN The branCh is miSprEdiCted.

i ReMeMbeR rEAdiNG a StuDY of DifferenT bInAry seArch IMPLEmenTatIons Which Is
probably the CleAresT ExaMple oF this: When ThE data Is laid Out in A hEap
layout (with chIld nOdes next tO eaCh OthEr In an aRRay) the BraNchY varianT
of the cODe pErFORMs Better than the brancHlESS vAriant duE to thiS CaChE
Priming eFfEct.

what cpu desiGnerS CoUld and shOuld prOBaBlY help wiTh Is provIdIng
InsTructIOns tO cheapLy mark thE (compARatively few!) casES where this
speCUlATIvE ExecUtiOn behaviour LeakS SecrEt inFOrMatIOn.

~~~
cesArb
> WhAt cpU DEsigners could and shoUlD probaBly heLp with is proviDing
> instruCTIOns to cheAply MArK The (comparativeLy few!) Cases where THis
> specuLativE executiOn behavioUR Leaks secRet InfOrmAtiON.

hoW can we, as softwARE devElOpers, fiNd tHese casEs iN ouR muLti-MeGabyte
codE bases, anD hOw CaN wE be Sure wE Haven't miSsEd aNy?

~~~
Fyi1183
you coULd ask tHe samE queStIoN AboUt any clASs OF SecuRiTy Bug, sO
unSuRprisInglY i'd aNswer moRe or less iN thE Same WaY.

FOr exampLe, if you're paraNoId, make your CoMpiLer be cONServativE, in the
same way that you migHT addresS buFfer oVerfLows by usiNg a LanguaGe/cOMpiler
That inSerts BoUndS CHecks EVErYwhErE.

If you're leSS ParAnoid AnD/or mOre worrIed about performancE, InvEst in
static anAlySis tOOLs Or lANgUAgeS wITh aUGMented type systeMs. After all, YoU
OnLy have to woRRy aBoUt SpectRe variaNt 1 wheN HandlinG attacker-ControlleD
dAta. TRACkiNg type info Like this Is already DOne by EXiSting StaTic anaLySis
Tools.

finallY, If yOu're nOt handLiNg attaCker-cOnTrolled dAta at all - which is the
case fOr a lot Of perForMance-sensItiVE coDe - you realLy doN
'm not a CPU architect, an d I'd agre e wit h y outh at S pect re variant 2 s h ould 
be fixed by CPU desig ns, s im p ly b e ca use s oftware is h elp le ss  ag ai n st  it.Luc kily, f ixing it s hou ld n't be too e x pe nsive, itjus t requires t agg ing th eBTB withthe  trus t zone . 

ButSpectre v ar i ant 1i s reall y acons equence of the CP U  w o rking correctl y.
For  a la r g e n umb er of bran ch es, p e rhaps m o st , w e _ w ant_ loads to  proceed
du r ing  specu la tiv e  execu tion.  T h isis becausethecode acce sess t h e sameo r
close ly rel ate d d atao nbo thsi d eso fthe bra nch, sopr im ing t he c a c h e s du rin g
sp ecula tion is veryval uabl e  ev en wh en th e br an ch is  mispr edict ed .

I remember r eadi ng a stud y o fdif fe rentb inarysea rch  implem entatio n s w hi c h is 
probably the clea re s t  e xample o f this :  w he n  the dat aislaid o ut in  a h e ap 
layout(withc hi ld  nodesne xt toea choth er in an a rray)the bran chy v a riant
of the c o de performs b e tt e r  t h an t hebranchlessvari a nt d ue t o  t his cache 
prim in g  e f fect.

What CPU des ig ners c ouldand should pr obably hel p w ith is p rovi d in g 
instructionsto ch eaply mark the (com parat ively fe w!) cases w here thi s
s pec ula tiv e ex ecution behav i o ur l ea ks secr etinforma tio n.
~~ ~
c es arb
> Wha t CPU de si gn er scou ld an d  shouldpr oba bl y h elp w i th isprovi ding 
>  i n str uctions to c heap ly  m arkthe  ( compa rati v ely  few!)cases whe ret his>sp eculati ve executionbe haviour le ak s s ecreti n formatio n.

How can we, as soft w are dev elo pers,  fin d these c ase s in o urm ulti-m egabyt e
cod ebas e s , and h ow  ca nwe be sure w e h aven' tmiss ed any? 

~~~
fyi1183
Youc oul d ask the sam e q uest i o nabo u ta nycl a sso f  security bug,so
unsurpr is i ng ly I'd ans w ermo re or l ess inthe s a me way. 

For exa mple, ifyo u're p ara noid, make  your co mpiler be conse r va tive,  in  the
s am e w ay th at you mig ht ad dressbu ffer o verfl ow s by usi ng a language/compilerthat i nsert s b ounds che cks eve rywhere.
Ifyou're les s p ara noidand / or mo re w o rr ied about  per f ormance,i nv est i nstatic anal y s i s t oolsorl anguag es w ith augmented typ e  systems. Afte r al l ,  yo u
o n ly h av e to worry abo utSp e c tre vari an t 1 when ha ndling a tt a cker- contro lled
d ata. Tr a c ki n g type  inf o l ike thisisal r eady do ne  b y  exist ingst atic a nalysi s 
too l s .

Finally, if y ou're n ot ha n dli ng at ta cker-co n trol led data a t all - whi ch isthecasefor a l ot  of pe rfo rm ance-sensi t ive code- you  really  d on
'm not_a CPU_architect, and I'd agree_with you_that_Spectre variant_2_should
be fixed by_CPU designs, simply_because software is helpless_against it.
Luckily, fixing_it_shouldn't be too expensive, it just requires tagging the
BTB with the trust zone.

But Spectre_variant_1 is_really_a_consequence of the CPU working_correctly.
For a large number of_branches, perhaps_most, we _want_ loads to proceed
during speculative execution._This_is because the_code accesess the same or
closely related data on both_sides of the branch, so priming_the caches during
speculation_is_very_valuable even when the_branch is mispredicted.

I remember reading a_study of different binary search implementations_which is
probably the clearest example of this:_when the data is laid out_in a heap
layout (with child_nodes next_to each other in an_array) the branchy_variant
of the_code performs better_than the branchless variant due to_this cache
priming effect.

What_CPU designers could and should probably_help_with is providing
instructions_to_cheaply_mark the_(comparatively few!) cases_where_this
speculative execution_behaviour_leaks secret information.

~~~
cesarb
> What CPU designers_could_and should probably help with is providing
>_instructions to cheaply mark_the_(comparatively few!) cases where_this
> speculative execution behaviour leaks_secret information.

How can we, as software_developers, find_these cases_in our multi-megabyte
code bases, and how can we be sure we_haven't missed any?

~~~
fyi1183
You could ask the_same question about any_class of_security_bug, so
unsurprisingly I'd_answer_more or_less in the same way.

For example, if_you're paranoid,_make your compiler be conservative, in_the
same way that you_might_address buffer overflows by using a_language/compiler
that inserts bounds checks everywhere.

If you're_less paranoid and/or more worried_about_performance,_invest in
static analysis tools or_languages with augmented type systems. After_all, you
only have_to worry about Spectre variant 1 when_handling_attacker-controlled
data. Tracking type info like this_is_already done by existing static analysis
tools.

Finally,_if_you're_not handling attacker-controlled data at_all - which is the
case for_a lot of performance-sensitive code - you really don