test_bpf.c 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933
  1. /*
  2. * Testsuite for BPF interpreter and BPF JIT compiler
  3. *
  4. * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/filter.h>
  19. #include <linux/bpf.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/if_vlan.h>
  23. #include <linux/random.h>
  24. #include <linux/highmem.h>
  25. /* General test specific settings */
  26. #define MAX_SUBTESTS 3
  27. #define MAX_TESTRUNS 10000
  28. #define MAX_DATA 128
  29. #define MAX_INSNS 512
  30. #define MAX_K 0xffffFFFF
  31. /* Few constants used to init test 'skb' */
  32. #define SKB_TYPE 3
  33. #define SKB_MARK 0x1234aaaa
  34. #define SKB_HASH 0x1234aaab
  35. #define SKB_QUEUE_MAP 123
  36. #define SKB_VLAN_TCI 0xffff
  37. #define SKB_DEV_IFINDEX 577
  38. #define SKB_DEV_TYPE 588
  39. /* Redefine REGs to make tests less verbose */
  40. #define R0 BPF_REG_0
  41. #define R1 BPF_REG_1
  42. #define R2 BPF_REG_2
  43. #define R3 BPF_REG_3
  44. #define R4 BPF_REG_4
  45. #define R5 BPF_REG_5
  46. #define R6 BPF_REG_6
  47. #define R7 BPF_REG_7
  48. #define R8 BPF_REG_8
  49. #define R9 BPF_REG_9
  50. #define R10 BPF_REG_10
  51. /* Flags that can be passed to test cases */
  52. #define FLAG_NO_DATA BIT(0)
  53. #define FLAG_EXPECTED_FAIL BIT(1)
  54. #define FLAG_SKB_FRAG BIT(2)
  55. enum {
  56. CLASSIC = BIT(6), /* Old BPF instructions only. */
  57. INTERNAL = BIT(7), /* Extended instruction set. */
  58. };
  59. #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
  60. struct bpf_test {
  61. const char *descr;
  62. union {
  63. struct sock_filter insns[MAX_INSNS];
  64. struct bpf_insn insns_int[MAX_INSNS];
  65. struct {
  66. void *insns;
  67. unsigned int len;
  68. } ptr;
  69. } u;
  70. __u8 aux;
  71. __u8 data[MAX_DATA];
  72. struct {
  73. int data_size;
  74. __u32 result;
  75. } test[MAX_SUBTESTS];
  76. int (*fill_helper)(struct bpf_test *self);
  77. int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
  78. __u8 frag_data[MAX_DATA];
  79. };
  80. /* Large test cases need separate allocation and fill handler. */
  81. static int bpf_fill_maxinsns1(struct bpf_test *self)
  82. {
  83. unsigned int len = BPF_MAXINSNS;
  84. struct sock_filter *insn;
  85. __u32 k = ~0;
  86. int i;
  87. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  88. if (!insn)
  89. return -ENOMEM;
  90. for (i = 0; i < len; i++, k--)
  91. insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
  92. self->u.ptr.insns = insn;
  93. self->u.ptr.len = len;
  94. return 0;
  95. }
  96. static int bpf_fill_maxinsns2(struct bpf_test *self)
  97. {
  98. unsigned int len = BPF_MAXINSNS;
  99. struct sock_filter *insn;
  100. int i;
  101. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  102. if (!insn)
  103. return -ENOMEM;
  104. for (i = 0; i < len; i++)
  105. insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
  106. self->u.ptr.insns = insn;
  107. self->u.ptr.len = len;
  108. return 0;
  109. }
  110. static int bpf_fill_maxinsns3(struct bpf_test *self)
  111. {
  112. unsigned int len = BPF_MAXINSNS;
  113. struct sock_filter *insn;
  114. struct rnd_state rnd;
  115. int i;
  116. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  117. if (!insn)
  118. return -ENOMEM;
  119. prandom_seed_state(&rnd, 3141592653589793238ULL);
  120. for (i = 0; i < len - 1; i++) {
  121. __u32 k = prandom_u32_state(&rnd);
  122. insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
  123. }
  124. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
  125. self->u.ptr.insns = insn;
  126. self->u.ptr.len = len;
  127. return 0;
  128. }
  129. static int bpf_fill_maxinsns4(struct bpf_test *self)
  130. {
  131. unsigned int len = BPF_MAXINSNS + 1;
  132. struct sock_filter *insn;
  133. int i;
  134. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  135. if (!insn)
  136. return -ENOMEM;
  137. for (i = 0; i < len; i++)
  138. insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
  139. self->u.ptr.insns = insn;
  140. self->u.ptr.len = len;
  141. return 0;
  142. }
  143. static int bpf_fill_maxinsns5(struct bpf_test *self)
  144. {
  145. unsigned int len = BPF_MAXINSNS;
  146. struct sock_filter *insn;
  147. int i;
  148. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  149. if (!insn)
  150. return -ENOMEM;
  151. insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
  152. for (i = 1; i < len - 1; i++)
  153. insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
  154. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
  155. self->u.ptr.insns = insn;
  156. self->u.ptr.len = len;
  157. return 0;
  158. }
  159. static int bpf_fill_maxinsns6(struct bpf_test *self)
  160. {
  161. unsigned int len = BPF_MAXINSNS;
  162. struct sock_filter *insn;
  163. int i;
  164. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  165. if (!insn)
  166. return -ENOMEM;
  167. for (i = 0; i < len - 1; i++)
  168. insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
  169. SKF_AD_VLAN_TAG_PRESENT);
  170. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
  171. self->u.ptr.insns = insn;
  172. self->u.ptr.len = len;
  173. return 0;
  174. }
  175. static int bpf_fill_maxinsns7(struct bpf_test *self)
  176. {
  177. unsigned int len = BPF_MAXINSNS;
  178. struct sock_filter *insn;
  179. int i;
  180. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  181. if (!insn)
  182. return -ENOMEM;
  183. for (i = 0; i < len - 4; i++)
  184. insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
  185. SKF_AD_CPU);
  186. insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
  187. insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
  188. SKF_AD_CPU);
  189. insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
  190. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
  191. self->u.ptr.insns = insn;
  192. self->u.ptr.len = len;
  193. return 0;
  194. }
  195. static int bpf_fill_maxinsns8(struct bpf_test *self)
  196. {
  197. unsigned int len = BPF_MAXINSNS;
  198. struct sock_filter *insn;
  199. int i, jmp_off = len - 3;
  200. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  201. if (!insn)
  202. return -ENOMEM;
  203. insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
  204. for (i = 1; i < len - 1; i++)
  205. insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
  206. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
  207. self->u.ptr.insns = insn;
  208. self->u.ptr.len = len;
  209. return 0;
  210. }
  211. static int bpf_fill_maxinsns9(struct bpf_test *self)
  212. {
  213. unsigned int len = BPF_MAXINSNS;
  214. struct bpf_insn *insn;
  215. int i;
  216. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  217. if (!insn)
  218. return -ENOMEM;
  219. insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
  220. insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
  221. insn[2] = BPF_EXIT_INSN();
  222. for (i = 3; i < len - 2; i++)
  223. insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
  224. insn[len - 2] = BPF_EXIT_INSN();
  225. insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
  226. self->u.ptr.insns = insn;
  227. self->u.ptr.len = len;
  228. return 0;
  229. }
  230. static int bpf_fill_maxinsns10(struct bpf_test *self)
  231. {
  232. unsigned int len = BPF_MAXINSNS, hlen = len - 2;
  233. struct bpf_insn *insn;
  234. int i;
  235. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  236. if (!insn)
  237. return -ENOMEM;
  238. for (i = 0; i < hlen / 2; i++)
  239. insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
  240. for (i = hlen - 1; i > hlen / 2; i--)
  241. insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
  242. insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
  243. insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
  244. insn[hlen + 1] = BPF_EXIT_INSN();
  245. self->u.ptr.insns = insn;
  246. self->u.ptr.len = len;
  247. return 0;
  248. }
  249. static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
  250. unsigned int plen)
  251. {
  252. struct sock_filter *insn;
  253. unsigned int rlen;
  254. int i, j;
  255. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  256. if (!insn)
  257. return -ENOMEM;
  258. rlen = (len % plen) - 1;
  259. for (i = 0; i + plen < len; i += plen)
  260. for (j = 0; j < plen; j++)
  261. insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
  262. plen - 1 - j, 0, 0);
  263. for (j = 0; j < rlen; j++)
  264. insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
  265. 0, 0);
  266. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
  267. self->u.ptr.insns = insn;
  268. self->u.ptr.len = len;
  269. return 0;
  270. }
  271. static int bpf_fill_maxinsns11(struct bpf_test *self)
  272. {
  273. /* Hits 70 passes on x86_64, so cannot get JITed there. */
  274. return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
  275. }
  276. static int bpf_fill_ja(struct bpf_test *self)
  277. {
  278. /* Hits exactly 11 passes on x86_64 JIT. */
  279. return __bpf_fill_ja(self, 12, 9);
  280. }
  281. static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
  282. {
  283. unsigned int len = BPF_MAXINSNS;
  284. struct sock_filter *insn;
  285. int i;
  286. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  287. if (!insn)
  288. return -ENOMEM;
  289. for (i = 0; i < len - 1; i += 2) {
  290. insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
  291. insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  292. SKF_AD_OFF + SKF_AD_CPU);
  293. }
  294. insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
  295. self->u.ptr.insns = insn;
  296. self->u.ptr.len = len;
  297. return 0;
  298. }
  299. #define PUSH_CNT 68
  300. /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
  301. static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
  302. {
  303. unsigned int len = BPF_MAXINSNS;
  304. struct bpf_insn *insn;
  305. int i = 0, j, k = 0;
  306. insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
  307. if (!insn)
  308. return -ENOMEM;
  309. insn[i++] = BPF_MOV64_REG(R6, R1);
  310. loop:
  311. for (j = 0; j < PUSH_CNT; j++) {
  312. insn[i++] = BPF_LD_ABS(BPF_B, 0);
  313. insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
  314. i++;
  315. insn[i++] = BPF_MOV64_REG(R1, R6);
  316. insn[i++] = BPF_MOV64_IMM(R2, 1);
  317. insn[i++] = BPF_MOV64_IMM(R3, 2);
  318. insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
  319. bpf_skb_vlan_push_proto.func - __bpf_call_base);
  320. insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
  321. i++;
  322. }
  323. for (j = 0; j < PUSH_CNT; j++) {
  324. insn[i++] = BPF_LD_ABS(BPF_B, 0);
  325. insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
  326. i++;
  327. insn[i++] = BPF_MOV64_REG(R1, R6);
  328. insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
  329. bpf_skb_vlan_pop_proto.func - __bpf_call_base);
  330. insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
  331. i++;
  332. }
  333. if (++k < 5)
  334. goto loop;
  335. for (; i < len - 1; i++)
  336. insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
  337. insn[len - 1] = BPF_EXIT_INSN();
  338. self->u.ptr.insns = insn;
  339. self->u.ptr.len = len;
  340. return 0;
  341. }
  342. static struct bpf_test tests[] = {
  343. {
  344. "TAX",
  345. .u.insns = {
  346. BPF_STMT(BPF_LD | BPF_IMM, 1),
  347. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  348. BPF_STMT(BPF_LD | BPF_IMM, 2),
  349. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  350. BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
  351. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  352. BPF_STMT(BPF_LD | BPF_LEN, 0),
  353. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  354. BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
  355. BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
  356. BPF_STMT(BPF_RET | BPF_A, 0)
  357. },
  358. CLASSIC,
  359. { 10, 20, 30, 40, 50 },
  360. { { 2, 10 }, { 3, 20 }, { 4, 30 } },
  361. },
  362. {
  363. "TXA",
  364. .u.insns = {
  365. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  366. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  367. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  368. BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
  369. },
  370. CLASSIC,
  371. { 10, 20, 30, 40, 50 },
  372. { { 1, 2 }, { 3, 6 }, { 4, 8 } },
  373. },
  374. {
  375. "ADD_SUB_MUL_K",
  376. .u.insns = {
  377. BPF_STMT(BPF_LD | BPF_IMM, 1),
  378. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
  379. BPF_STMT(BPF_LDX | BPF_IMM, 3),
  380. BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
  381. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
  382. BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
  383. BPF_STMT(BPF_RET | BPF_A, 0)
  384. },
  385. CLASSIC | FLAG_NO_DATA,
  386. { },
  387. { { 0, 0xfffffffd } }
  388. },
  389. {
  390. "DIV_MOD_KX",
  391. .u.insns = {
  392. BPF_STMT(BPF_LD | BPF_IMM, 8),
  393. BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
  394. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  395. BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
  396. BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
  397. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  398. BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
  399. BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
  400. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  401. BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
  402. BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
  403. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  404. BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
  405. BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
  406. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  407. BPF_STMT(BPF_RET | BPF_A, 0)
  408. },
  409. CLASSIC | FLAG_NO_DATA,
  410. { },
  411. { { 0, 0x20000000 } }
  412. },
  413. {
  414. "AND_OR_LSH_K",
  415. .u.insns = {
  416. BPF_STMT(BPF_LD | BPF_IMM, 0xff),
  417. BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
  418. BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
  419. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  420. BPF_STMT(BPF_LD | BPF_IMM, 0xf),
  421. BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
  422. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  423. BPF_STMT(BPF_RET | BPF_A, 0)
  424. },
  425. CLASSIC | FLAG_NO_DATA,
  426. { },
  427. { { 0, 0x800000ff }, { 1, 0x800000ff } },
  428. },
  429. {
  430. "LD_IMM_0",
  431. .u.insns = {
  432. BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
  433. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
  434. BPF_STMT(BPF_RET | BPF_K, 0),
  435. BPF_STMT(BPF_RET | BPF_K, 1),
  436. },
  437. CLASSIC,
  438. { },
  439. { { 1, 1 } },
  440. },
  441. {
  442. "LD_IND",
  443. .u.insns = {
  444. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  445. BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
  446. BPF_STMT(BPF_RET | BPF_K, 1)
  447. },
  448. CLASSIC,
  449. { },
  450. { { 1, 0 }, { 10, 0 }, { 60, 0 } },
  451. },
  452. {
  453. "LD_ABS",
  454. .u.insns = {
  455. BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
  456. BPF_STMT(BPF_RET | BPF_K, 1)
  457. },
  458. CLASSIC,
  459. { },
  460. { { 1, 0 }, { 10, 0 }, { 60, 0 } },
  461. },
  462. {
  463. "LD_ABS_LL",
  464. .u.insns = {
  465. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
  466. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  467. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
  468. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  469. BPF_STMT(BPF_RET | BPF_A, 0)
  470. },
  471. CLASSIC,
  472. { 1, 2, 3 },
  473. { { 1, 0 }, { 2, 3 } },
  474. },
  475. {
  476. "LD_IND_LL",
  477. .u.insns = {
  478. BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
  479. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  480. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  481. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  482. BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
  483. BPF_STMT(BPF_RET | BPF_A, 0)
  484. },
  485. CLASSIC,
  486. { 1, 2, 3, 0xff },
  487. { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
  488. },
  489. {
  490. "LD_ABS_NET",
  491. .u.insns = {
  492. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
  493. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  494. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
  495. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  496. BPF_STMT(BPF_RET | BPF_A, 0)
  497. },
  498. CLASSIC,
  499. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
  500. { { 15, 0 }, { 16, 3 } },
  501. },
  502. {
  503. "LD_IND_NET",
  504. .u.insns = {
  505. BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
  506. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  507. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  508. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  509. BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
  510. BPF_STMT(BPF_RET | BPF_A, 0)
  511. },
  512. CLASSIC,
  513. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
  514. { { 14, 0 }, { 15, 1 }, { 17, 3 } },
  515. },
  516. {
  517. "LD_PKTTYPE",
  518. .u.insns = {
  519. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  520. SKF_AD_OFF + SKF_AD_PKTTYPE),
  521. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
  522. BPF_STMT(BPF_RET | BPF_K, 1),
  523. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  524. SKF_AD_OFF + SKF_AD_PKTTYPE),
  525. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
  526. BPF_STMT(BPF_RET | BPF_K, 1),
  527. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  528. SKF_AD_OFF + SKF_AD_PKTTYPE),
  529. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
  530. BPF_STMT(BPF_RET | BPF_K, 1),
  531. BPF_STMT(BPF_RET | BPF_A, 0)
  532. },
  533. CLASSIC,
  534. { },
  535. { { 1, 3 }, { 10, 3 } },
  536. },
  537. {
  538. "LD_MARK",
  539. .u.insns = {
  540. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  541. SKF_AD_OFF + SKF_AD_MARK),
  542. BPF_STMT(BPF_RET | BPF_A, 0)
  543. },
  544. CLASSIC,
  545. { },
  546. { { 1, SKB_MARK}, { 10, SKB_MARK} },
  547. },
  548. {
  549. "LD_RXHASH",
  550. .u.insns = {
  551. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  552. SKF_AD_OFF + SKF_AD_RXHASH),
  553. BPF_STMT(BPF_RET | BPF_A, 0)
  554. },
  555. CLASSIC,
  556. { },
  557. { { 1, SKB_HASH}, { 10, SKB_HASH} },
  558. },
  559. {
  560. "LD_QUEUE",
  561. .u.insns = {
  562. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  563. SKF_AD_OFF + SKF_AD_QUEUE),
  564. BPF_STMT(BPF_RET | BPF_A, 0)
  565. },
  566. CLASSIC,
  567. { },
  568. { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
  569. },
  570. {
  571. "LD_PROTOCOL",
  572. .u.insns = {
  573. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
  574. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
  575. BPF_STMT(BPF_RET | BPF_K, 0),
  576. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  577. SKF_AD_OFF + SKF_AD_PROTOCOL),
  578. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  579. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
  580. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
  581. BPF_STMT(BPF_RET | BPF_K, 0),
  582. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  583. BPF_STMT(BPF_RET | BPF_A, 0)
  584. },
  585. CLASSIC,
  586. { 10, 20, 30 },
  587. { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
  588. },
  589. {
  590. "LD_VLAN_TAG",
  591. .u.insns = {
  592. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  593. SKF_AD_OFF + SKF_AD_VLAN_TAG),
  594. BPF_STMT(BPF_RET | BPF_A, 0)
  595. },
  596. CLASSIC,
  597. { },
  598. {
  599. { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
  600. { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
  601. },
  602. },
  603. {
  604. "LD_VLAN_TAG_PRESENT",
  605. .u.insns = {
  606. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  607. SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
  608. BPF_STMT(BPF_RET | BPF_A, 0)
  609. },
  610. CLASSIC,
  611. { },
  612. {
  613. { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
  614. { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
  615. },
  616. },
  617. {
  618. "LD_IFINDEX",
  619. .u.insns = {
  620. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  621. SKF_AD_OFF + SKF_AD_IFINDEX),
  622. BPF_STMT(BPF_RET | BPF_A, 0)
  623. },
  624. CLASSIC,
  625. { },
  626. { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
  627. },
  628. {
  629. "LD_HATYPE",
  630. .u.insns = {
  631. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  632. SKF_AD_OFF + SKF_AD_HATYPE),
  633. BPF_STMT(BPF_RET | BPF_A, 0)
  634. },
  635. CLASSIC,
  636. { },
  637. { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
  638. },
  639. {
  640. "LD_CPU",
  641. .u.insns = {
  642. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  643. SKF_AD_OFF + SKF_AD_CPU),
  644. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  645. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  646. SKF_AD_OFF + SKF_AD_CPU),
  647. BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
  648. BPF_STMT(BPF_RET | BPF_A, 0)
  649. },
  650. CLASSIC,
  651. { },
  652. { { 1, 0 }, { 10, 0 } },
  653. },
  654. {
  655. "LD_NLATTR",
  656. .u.insns = {
  657. BPF_STMT(BPF_LDX | BPF_IMM, 2),
  658. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  659. BPF_STMT(BPF_LDX | BPF_IMM, 3),
  660. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  661. SKF_AD_OFF + SKF_AD_NLATTR),
  662. BPF_STMT(BPF_RET | BPF_A, 0)
  663. },
  664. CLASSIC,
  665. #ifdef __BIG_ENDIAN
  666. { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
  667. #else
  668. { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
  669. #endif
  670. { { 4, 0 }, { 20, 6 } },
  671. },
  672. {
  673. "LD_NLATTR_NEST",
  674. .u.insns = {
  675. BPF_STMT(BPF_LD | BPF_IMM, 2),
  676. BPF_STMT(BPF_LDX | BPF_IMM, 3),
  677. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  678. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  679. BPF_STMT(BPF_LD | BPF_IMM, 2),
  680. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  681. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  682. BPF_STMT(BPF_LD | BPF_IMM, 2),
  683. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  684. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  685. BPF_STMT(BPF_LD | BPF_IMM, 2),
  686. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  687. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  688. BPF_STMT(BPF_LD | BPF_IMM, 2),
  689. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  690. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  691. BPF_STMT(BPF_LD | BPF_IMM, 2),
  692. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  693. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  694. BPF_STMT(BPF_LD | BPF_IMM, 2),
  695. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  696. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  697. BPF_STMT(BPF_LD | BPF_IMM, 2),
  698. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  699. SKF_AD_OFF + SKF_AD_NLATTR_NEST),
  700. BPF_STMT(BPF_RET | BPF_A, 0)
  701. },
  702. CLASSIC,
  703. #ifdef __BIG_ENDIAN
  704. { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
  705. #else
  706. { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
  707. #endif
  708. { { 4, 0 }, { 20, 10 } },
  709. },
  710. {
  711. "LD_PAYLOAD_OFF",
  712. .u.insns = {
  713. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  714. SKF_AD_OFF + SKF_AD_PAY_OFFSET),
  715. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  716. SKF_AD_OFF + SKF_AD_PAY_OFFSET),
  717. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  718. SKF_AD_OFF + SKF_AD_PAY_OFFSET),
  719. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  720. SKF_AD_OFF + SKF_AD_PAY_OFFSET),
  721. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  722. SKF_AD_OFF + SKF_AD_PAY_OFFSET),
  723. BPF_STMT(BPF_RET | BPF_A, 0)
  724. },
  725. CLASSIC,
  726. /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
  727. * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
  728. * id 9737, seq 1, length 64
  729. */
  730. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  731. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  732. 0x08, 0x00,
  733. 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
  734. 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
  735. { { 30, 0 }, { 100, 42 } },
  736. },
  737. {
  738. "LD_ANC_XOR",
  739. .u.insns = {
  740. BPF_STMT(BPF_LD | BPF_IMM, 10),
  741. BPF_STMT(BPF_LDX | BPF_IMM, 300),
  742. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  743. SKF_AD_OFF + SKF_AD_ALU_XOR_X),
  744. BPF_STMT(BPF_RET | BPF_A, 0)
  745. },
  746. CLASSIC,
  747. { },
  748. { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
  749. },
  750. {
  751. "SPILL_FILL",
  752. .u.insns = {
  753. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  754. BPF_STMT(BPF_LD | BPF_IMM, 2),
  755. BPF_STMT(BPF_ALU | BPF_RSH, 1),
  756. BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
  757. BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
  758. BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
  759. BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
  760. BPF_STMT(BPF_STX, 15), /* M3 = len */
  761. BPF_STMT(BPF_LDX | BPF_MEM, 1),
  762. BPF_STMT(BPF_LD | BPF_MEM, 2),
  763. BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
  764. BPF_STMT(BPF_LDX | BPF_MEM, 15),
  765. BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
  766. BPF_STMT(BPF_RET | BPF_A, 0)
  767. },
  768. CLASSIC,
  769. { },
  770. { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
  771. },
  772. {
  773. "JEQ",
  774. .u.insns = {
  775. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  776. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
  777. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
  778. BPF_STMT(BPF_RET | BPF_K, 1),
  779. BPF_STMT(BPF_RET | BPF_K, MAX_K)
  780. },
  781. CLASSIC,
  782. { 3, 3, 3, 3, 3 },
  783. { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
  784. },
  785. {
  786. "JGT",
  787. .u.insns = {
  788. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  789. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
  790. BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
  791. BPF_STMT(BPF_RET | BPF_K, 1),
  792. BPF_STMT(BPF_RET | BPF_K, MAX_K)
  793. },
  794. CLASSIC,
  795. { 4, 4, 4, 3, 3 },
  796. { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
  797. },
  798. {
  799. "JGE",
  800. .u.insns = {
  801. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  802. BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
  803. BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
  804. BPF_STMT(BPF_RET | BPF_K, 10),
  805. BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
  806. BPF_STMT(BPF_RET | BPF_K, 20),
  807. BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
  808. BPF_STMT(BPF_RET | BPF_K, 30),
  809. BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
  810. BPF_STMT(BPF_RET | BPF_K, 40),
  811. BPF_STMT(BPF_RET | BPF_K, MAX_K)
  812. },
  813. CLASSIC,
  814. { 1, 2, 3, 4, 5 },
  815. { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
  816. },
  817. {
  818. "JSET",
  819. .u.insns = {
  820. BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
  821. BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
  822. BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
  823. BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
  824. BPF_STMT(BPF_LDX | BPF_LEN, 0),
  825. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  826. BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
  827. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  828. BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
  829. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
  830. BPF_STMT(BPF_RET | BPF_K, 10),
  831. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
  832. BPF_STMT(BPF_RET | BPF_K, 20),
  833. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
  834. BPF_STMT(BPF_RET | BPF_K, 30),
  835. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
  836. BPF_STMT(BPF_RET | BPF_K, 30),
  837. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
  838. BPF_STMT(BPF_RET | BPF_K, 30),
  839. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
  840. BPF_STMT(BPF_RET | BPF_K, 30),
  841. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
  842. BPF_STMT(BPF_RET | BPF_K, 30),
  843. BPF_STMT(BPF_RET | BPF_K, MAX_K)
  844. },
  845. CLASSIC,
  846. { 0, 0xAA, 0x55, 1 },
  847. { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
  848. },
  849. {
  850. "tcpdump port 22",
  851. .u.insns = {
  852. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
  853. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
  854. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
  855. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
  856. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
  857. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
  858. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
  859. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
  860. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
  861. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
  862. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
  863. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
  864. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
  865. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
  866. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
  867. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
  868. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
  869. BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
  870. BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
  871. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
  872. BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
  873. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
  874. BPF_STMT(BPF_RET | BPF_K, 0xffff),
  875. BPF_STMT(BPF_RET | BPF_K, 0),
  876. },
  877. CLASSIC,
  878. /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
  879. * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
  880. * seq 1305692979:1305693027, ack 3650467037, win 65535,
  881. * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
  882. */
  883. { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
  884. 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
  885. 0x08, 0x00,
  886. 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
  887. 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
  888. 0x0a, 0x01, 0x01, 0x95, /* ip src */
  889. 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
  890. 0xc2, 0x24,
  891. 0x00, 0x16 /* dst port */ },
  892. { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
  893. },
  894. {
  895. "tcpdump complex",
  896. .u.insns = {
  897. /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
  898. * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
  899. * (len > 115 or len < 30000000000)' -d
  900. */
  901. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
  902. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
  903. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
  904. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
  905. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
  906. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
  907. BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
  908. BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
  909. BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
  910. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
  911. BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
  912. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
  913. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
  914. BPF_STMT(BPF_ST, 1),
  915. BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
  916. BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
  917. BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
  918. BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
  919. BPF_STMT(BPF_LD | BPF_MEM, 1),
  920. BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
  921. BPF_STMT(BPF_ST, 5),
  922. BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
  923. BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
  924. BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
  925. BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
  926. BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
  927. BPF_STMT(BPF_LD | BPF_MEM, 5),
  928. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
  929. BPF_STMT(BPF_LD | BPF_LEN, 0),
  930. BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
  931. BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
  932. BPF_STMT(BPF_RET | BPF_K, 0xffff),
  933. BPF_STMT(BPF_RET | BPF_K, 0),
  934. },
  935. CLASSIC,
  936. { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
  937. 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
  938. 0x08, 0x00,
  939. 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
  940. 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
  941. 0x0a, 0x01, 0x01, 0x95, /* ip src */
  942. 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
  943. 0xc2, 0x24,
  944. 0x00, 0x16 /* dst port */ },
  945. { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
  946. },
  947. {
  948. "RET_A",
  949. .u.insns = {
  950. /* check that unitialized X and A contain zeros */
  951. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  952. BPF_STMT(BPF_RET | BPF_A, 0)
  953. },
  954. CLASSIC,
  955. { },
  956. { {1, 0}, {2, 0} },
  957. },
  958. {
  959. "INT: ADD trivial",
  960. .u.insns_int = {
  961. BPF_ALU64_IMM(BPF_MOV, R1, 1),
  962. BPF_ALU64_IMM(BPF_ADD, R1, 2),
  963. BPF_ALU64_IMM(BPF_MOV, R2, 3),
  964. BPF_ALU64_REG(BPF_SUB, R1, R2),
  965. BPF_ALU64_IMM(BPF_ADD, R1, -1),
  966. BPF_ALU64_IMM(BPF_MUL, R1, 3),
  967. BPF_ALU64_REG(BPF_MOV, R0, R1),
  968. BPF_EXIT_INSN(),
  969. },
  970. INTERNAL,
  971. { },
  972. { { 0, 0xfffffffd } }
  973. },
  974. {
  975. "INT: MUL_X",
  976. .u.insns_int = {
  977. BPF_ALU64_IMM(BPF_MOV, R0, -1),
  978. BPF_ALU64_IMM(BPF_MOV, R1, -1),
  979. BPF_ALU64_IMM(BPF_MOV, R2, 3),
  980. BPF_ALU64_REG(BPF_MUL, R1, R2),
  981. BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
  982. BPF_EXIT_INSN(),
  983. BPF_ALU64_IMM(BPF_MOV, R0, 1),
  984. BPF_EXIT_INSN(),
  985. },
  986. INTERNAL,
  987. { },
  988. { { 0, 1 } }
  989. },
  990. {
  991. "INT: MUL_X2",
  992. .u.insns_int = {
  993. BPF_ALU32_IMM(BPF_MOV, R0, -1),
  994. BPF_ALU32_IMM(BPF_MOV, R1, -1),
  995. BPF_ALU32_IMM(BPF_MOV, R2, 3),
  996. BPF_ALU64_REG(BPF_MUL, R1, R2),
  997. BPF_ALU64_IMM(BPF_RSH, R1, 8),
  998. BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
  999. BPF_EXIT_INSN(),
  1000. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  1001. BPF_EXIT_INSN(),
  1002. },
  1003. INTERNAL,
  1004. { },
  1005. { { 0, 1 } }
  1006. },
  1007. {
  1008. "INT: MUL32_X",
  1009. .u.insns_int = {
  1010. BPF_ALU32_IMM(BPF_MOV, R0, -1),
  1011. BPF_ALU64_IMM(BPF_MOV, R1, -1),
  1012. BPF_ALU32_IMM(BPF_MOV, R2, 3),
  1013. BPF_ALU32_REG(BPF_MUL, R1, R2),
  1014. BPF_ALU64_IMM(BPF_RSH, R1, 8),
  1015. BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
  1016. BPF_EXIT_INSN(),
  1017. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  1018. BPF_EXIT_INSN(),
  1019. },
  1020. INTERNAL,
  1021. { },
  1022. { { 0, 1 } }
  1023. },
  1024. {
  1025. /* Have to test all register combinations, since
  1026. * JITing of different registers will produce
  1027. * different asm code.
  1028. */
  1029. "INT: ADD 64-bit",
  1030. .u.insns_int = {
  1031. BPF_ALU64_IMM(BPF_MOV, R0, 0),
  1032. BPF_ALU64_IMM(BPF_MOV, R1, 1),
  1033. BPF_ALU64_IMM(BPF_MOV, R2, 2),
  1034. BPF_ALU64_IMM(BPF_MOV, R3, 3),
  1035. BPF_ALU64_IMM(BPF_MOV, R4, 4),
  1036. BPF_ALU64_IMM(BPF_MOV, R5, 5),
  1037. BPF_ALU64_IMM(BPF_MOV, R6, 6),
  1038. BPF_ALU64_IMM(BPF_MOV, R7, 7),
  1039. BPF_ALU64_IMM(BPF_MOV, R8, 8),
  1040. BPF_ALU64_IMM(BPF_MOV, R9, 9),
  1041. BPF_ALU64_IMM(BPF_ADD, R0, 20),
  1042. BPF_ALU64_IMM(BPF_ADD, R1, 20),
  1043. BPF_ALU64_IMM(BPF_ADD, R2, 20),
  1044. BPF_ALU64_IMM(BPF_ADD, R3, 20),
  1045. BPF_ALU64_IMM(BPF_ADD, R4, 20),
  1046. BPF_ALU64_IMM(BPF_ADD, R5, 20),
  1047. BPF_ALU64_IMM(BPF_ADD, R6, 20),
  1048. BPF_ALU64_IMM(BPF_ADD, R7, 20),
  1049. BPF_ALU64_IMM(BPF_ADD, R8, 20),
  1050. BPF_ALU64_IMM(BPF_ADD, R9, 20),
  1051. BPF_ALU64_IMM(BPF_SUB, R0, 10),
  1052. BPF_ALU64_IMM(BPF_SUB, R1, 10),
  1053. BPF_ALU64_IMM(BPF_SUB, R2, 10),
  1054. BPF_ALU64_IMM(BPF_SUB, R3, 10),
  1055. BPF_ALU64_IMM(BPF_SUB, R4, 10),
  1056. BPF_ALU64_IMM(BPF_SUB, R5, 10),
  1057. BPF_ALU64_IMM(BPF_SUB, R6, 10),
  1058. BPF_ALU64_IMM(BPF_SUB, R7, 10),
  1059. BPF_ALU64_IMM(BPF_SUB, R8, 10),
  1060. BPF_ALU64_IMM(BPF_SUB, R9, 10),
  1061. BPF_ALU64_REG(BPF_ADD, R0, R0),
  1062. BPF_ALU64_REG(BPF_ADD, R0, R1),
  1063. BPF_ALU64_REG(BPF_ADD, R0, R2),
  1064. BPF_ALU64_REG(BPF_ADD, R0, R3),
  1065. BPF_ALU64_REG(BPF_ADD, R0, R4),
  1066. BPF_ALU64_REG(BPF_ADD, R0, R5),
  1067. BPF_ALU64_REG(BPF_ADD, R0, R6),
  1068. BPF_ALU64_REG(BPF_ADD, R0, R7),
  1069. BPF_ALU64_REG(BPF_ADD, R0, R8),
  1070. BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
  1071. BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
  1072. BPF_EXIT_INSN(),
  1073. BPF_ALU64_REG(BPF_ADD, R1, R0),
  1074. BPF_ALU64_REG(BPF_ADD, R1, R1),
  1075. BPF_ALU64_REG(BPF_ADD, R1, R2),
  1076. BPF_ALU64_REG(BPF_ADD, R1, R3),
  1077. BPF_ALU64_REG(BPF_ADD, R1, R4),
  1078. BPF_ALU64_REG(BPF_ADD, R1, R5),
  1079. BPF_ALU64_REG(BPF_ADD, R1, R6),
  1080. BPF_ALU64_REG(BPF_ADD, R1, R7),
  1081. BPF_ALU64_REG(BPF_ADD, R1, R8),
  1082. BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
  1083. BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
  1084. BPF_EXIT_INSN(),
  1085. BPF_ALU64_REG(BPF_ADD, R2, R0),
  1086. BPF_ALU64_REG(BPF_ADD, R2, R1),
  1087. BPF_ALU64_REG(BPF_ADD, R2, R2),
  1088. BPF_ALU64_REG(BPF_ADD, R2, R3),
  1089. BPF_ALU64_REG(BPF_ADD, R2, R4),
  1090. BPF_ALU64_REG(BPF_ADD, R2, R5),
  1091. BPF_ALU64_REG(BPF_ADD, R2, R6),
  1092. BPF_ALU64_REG(BPF_ADD, R2, R7),
  1093. BPF_ALU64_REG(BPF_ADD, R2, R8),
  1094. BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
  1095. BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
  1096. BPF_EXIT_INSN(),
  1097. BPF_ALU64_REG(BPF_ADD, R3, R0),
  1098. BPF_ALU64_REG(BPF_ADD, R3, R1),
  1099. BPF_ALU64_REG(BPF_ADD, R3, R2),
  1100. BPF_ALU64_REG(BPF_ADD, R3, R3),
  1101. BPF_ALU64_REG(BPF_ADD, R3, R4),
  1102. BPF_ALU64_REG(BPF_ADD, R3, R5),
  1103. BPF_ALU64_REG(BPF_ADD, R3, R6),
  1104. BPF_ALU64_REG(BPF_ADD, R3, R7),
  1105. BPF_ALU64_REG(BPF_ADD, R3, R8),
  1106. BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
  1107. BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
  1108. BPF_EXIT_INSN(),
  1109. BPF_ALU64_REG(BPF_ADD, R4, R0),
  1110. BPF_ALU64_REG(BPF_ADD, R4, R1),
  1111. BPF_ALU64_REG(BPF_ADD, R4, R2),
  1112. BPF_ALU64_REG(BPF_ADD, R4, R3),
  1113. BPF_ALU64_REG(BPF_ADD, R4, R4),
  1114. BPF_ALU64_REG(BPF_ADD, R4, R5),
  1115. BPF_ALU64_REG(BPF_ADD, R4, R6),
  1116. BPF_ALU64_REG(BPF_ADD, R4, R7),
  1117. BPF_ALU64_REG(BPF_ADD, R4, R8),
  1118. BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
  1119. BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
  1120. BPF_EXIT_INSN(),
  1121. BPF_ALU64_REG(BPF_ADD, R5, R0),
  1122. BPF_ALU64_REG(BPF_ADD, R5, R1),
  1123. BPF_ALU64_REG(BPF_ADD, R5, R2),
  1124. BPF_ALU64_REG(BPF_ADD, R5, R3),
  1125. BPF_ALU64_REG(BPF_ADD, R5, R4),
  1126. BPF_ALU64_REG(BPF_ADD, R5, R5),
  1127. BPF_ALU64_REG(BPF_ADD, R5, R6),
  1128. BPF_ALU64_REG(BPF_ADD, R5, R7),
  1129. BPF_ALU64_REG(BPF_ADD, R5, R8),
  1130. BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
  1131. BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
  1132. BPF_EXIT_INSN(),
  1133. BPF_ALU64_REG(BPF_ADD, R6, R0),
  1134. BPF_ALU64_REG(BPF_ADD, R6, R1),
  1135. BPF_ALU64_REG(BPF_ADD, R6, R2),
  1136. BPF_ALU64_REG(BPF_ADD, R6, R3),
  1137. BPF_ALU64_REG(BPF_ADD, R6, R4),
  1138. BPF_ALU64_REG(BPF_ADD, R6, R5),
  1139. BPF_ALU64_REG(BPF_ADD, R6, R6),
  1140. BPF_ALU64_REG(BPF_ADD, R6, R7),
  1141. BPF_ALU64_REG(BPF_ADD, R6, R8),
  1142. BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
  1143. BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
  1144. BPF_EXIT_INSN(),
  1145. BPF_ALU64_REG(BPF_ADD, R7, R0),
  1146. BPF_ALU64_REG(BPF_ADD, R7, R1),
  1147. BPF_ALU64_REG(BPF_ADD, R7, R2),
  1148. BPF_ALU64_REG(BPF_ADD, R7, R3),
  1149. BPF_ALU64_REG(BPF_ADD, R7, R4),
  1150. BPF_ALU64_REG(BPF_ADD, R7, R5),
  1151. BPF_ALU64_REG(BPF_ADD, R7, R6),
  1152. BPF_ALU64_REG(BPF_ADD, R7, R7),
  1153. BPF_ALU64_REG(BPF_ADD, R7, R8),
  1154. BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
  1155. BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
  1156. BPF_EXIT_INSN(),
  1157. BPF_ALU64_REG(BPF_ADD, R8, R0),
  1158. BPF_ALU64_REG(BPF_ADD, R8, R1),
  1159. BPF_ALU64_REG(BPF_ADD, R8, R2),
  1160. BPF_ALU64_REG(BPF_ADD, R8, R3),
  1161. BPF_ALU64_REG(BPF_ADD, R8, R4),
  1162. BPF_ALU64_REG(BPF_ADD, R8, R5),
  1163. BPF_ALU64_REG(BPF_ADD, R8, R6),
  1164. BPF_ALU64_REG(BPF_ADD, R8, R7),
  1165. BPF_ALU64_REG(BPF_ADD, R8, R8),
  1166. BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
  1167. BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
  1168. BPF_EXIT_INSN(),
  1169. BPF_ALU64_REG(BPF_ADD, R9, R0),
  1170. BPF_ALU64_REG(BPF_ADD, R9, R1),
  1171. BPF_ALU64_REG(BPF_ADD, R9, R2),
  1172. BPF_ALU64_REG(BPF_ADD, R9, R3),
  1173. BPF_ALU64_REG(BPF_ADD, R9, R4),
  1174. BPF_ALU64_REG(BPF_ADD, R9, R5),
  1175. BPF_ALU64_REG(BPF_ADD, R9, R6),
  1176. BPF_ALU64_REG(BPF_ADD, R9, R7),
  1177. BPF_ALU64_REG(BPF_ADD, R9, R8),
  1178. BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
  1179. BPF_ALU64_REG(BPF_MOV, R0, R9),
  1180. BPF_EXIT_INSN(),
  1181. },
  1182. INTERNAL,
  1183. { },
  1184. { { 0, 2957380 } }
  1185. },
  1186. {
  1187. "INT: ADD 32-bit",
  1188. .u.insns_int = {
  1189. BPF_ALU32_IMM(BPF_MOV, R0, 20),
  1190. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  1191. BPF_ALU32_IMM(BPF_MOV, R2, 2),
  1192. BPF_ALU32_IMM(BPF_MOV, R3, 3),
  1193. BPF_ALU32_IMM(BPF_MOV, R4, 4),
  1194. BPF_ALU32_IMM(BPF_MOV, R5, 5),
  1195. BPF_ALU32_IMM(BPF_MOV, R6, 6),
  1196. BPF_ALU32_IMM(BPF_MOV, R7, 7),
  1197. BPF_ALU32_IMM(BPF_MOV, R8, 8),
  1198. BPF_ALU32_IMM(BPF_MOV, R9, 9),
  1199. BPF_ALU64_IMM(BPF_ADD, R1, 10),
  1200. BPF_ALU64_IMM(BPF_ADD, R2, 10),
  1201. BPF_ALU64_IMM(BPF_ADD, R3, 10),
  1202. BPF_ALU64_IMM(BPF_ADD, R4, 10),
  1203. BPF_ALU64_IMM(BPF_ADD, R5, 10),
  1204. BPF_ALU64_IMM(BPF_ADD, R6, 10),
  1205. BPF_ALU64_IMM(BPF_ADD, R7, 10),
  1206. BPF_ALU64_IMM(BPF_ADD, R8, 10),
  1207. BPF_ALU64_IMM(BPF_ADD, R9, 10),
  1208. BPF_ALU32_REG(BPF_ADD, R0, R1),
  1209. BPF_ALU32_REG(BPF_ADD, R0, R2),
  1210. BPF_ALU32_REG(BPF_ADD, R0, R3),
  1211. BPF_ALU32_REG(BPF_ADD, R0, R4),
  1212. BPF_ALU32_REG(BPF_ADD, R0, R5),
  1213. BPF_ALU32_REG(BPF_ADD, R0, R6),
  1214. BPF_ALU32_REG(BPF_ADD, R0, R7),
  1215. BPF_ALU32_REG(BPF_ADD, R0, R8),
  1216. BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
  1217. BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
  1218. BPF_EXIT_INSN(),
  1219. BPF_ALU32_REG(BPF_ADD, R1, R0),
  1220. BPF_ALU32_REG(BPF_ADD, R1, R1),
  1221. BPF_ALU32_REG(BPF_ADD, R1, R2),
  1222. BPF_ALU32_REG(BPF_ADD, R1, R3),
  1223. BPF_ALU32_REG(BPF_ADD, R1, R4),
  1224. BPF_ALU32_REG(BPF_ADD, R1, R5),
  1225. BPF_ALU32_REG(BPF_ADD, R1, R6),
  1226. BPF_ALU32_REG(BPF_ADD, R1, R7),
  1227. BPF_ALU32_REG(BPF_ADD, R1, R8),
  1228. BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
  1229. BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
  1230. BPF_EXIT_INSN(),
  1231. BPF_ALU32_REG(BPF_ADD, R2, R0),
  1232. BPF_ALU32_REG(BPF_ADD, R2, R1),
  1233. BPF_ALU32_REG(BPF_ADD, R2, R2),
  1234. BPF_ALU32_REG(BPF_ADD, R2, R3),
  1235. BPF_ALU32_REG(BPF_ADD, R2, R4),
  1236. BPF_ALU32_REG(BPF_ADD, R2, R5),
  1237. BPF_ALU32_REG(BPF_ADD, R2, R6),
  1238. BPF_ALU32_REG(BPF_ADD, R2, R7),
  1239. BPF_ALU32_REG(BPF_ADD, R2, R8),
  1240. BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
  1241. BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
  1242. BPF_EXIT_INSN(),
  1243. BPF_ALU32_REG(BPF_ADD, R3, R0),
  1244. BPF_ALU32_REG(BPF_ADD, R3, R1),
  1245. BPF_ALU32_REG(BPF_ADD, R3, R2),
  1246. BPF_ALU32_REG(BPF_ADD, R3, R3),
  1247. BPF_ALU32_REG(BPF_ADD, R3, R4),
  1248. BPF_ALU32_REG(BPF_ADD, R3, R5),
  1249. BPF_ALU32_REG(BPF_ADD, R3, R6),
  1250. BPF_ALU32_REG(BPF_ADD, R3, R7),
  1251. BPF_ALU32_REG(BPF_ADD, R3, R8),
  1252. BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
  1253. BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
  1254. BPF_EXIT_INSN(),
  1255. BPF_ALU32_REG(BPF_ADD, R4, R0),
  1256. BPF_ALU32_REG(BPF_ADD, R4, R1),
  1257. BPF_ALU32_REG(BPF_ADD, R4, R2),
  1258. BPF_ALU32_REG(BPF_ADD, R4, R3),
  1259. BPF_ALU32_REG(BPF_ADD, R4, R4),
  1260. BPF_ALU32_REG(BPF_ADD, R4, R5),
  1261. BPF_ALU32_REG(BPF_ADD, R4, R6),
  1262. BPF_ALU32_REG(BPF_ADD, R4, R7),
  1263. BPF_ALU32_REG(BPF_ADD, R4, R8),
  1264. BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
  1265. BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
  1266. BPF_EXIT_INSN(),
  1267. BPF_ALU32_REG(BPF_ADD, R5, R0),
  1268. BPF_ALU32_REG(BPF_ADD, R5, R1),
  1269. BPF_ALU32_REG(BPF_ADD, R5, R2),
  1270. BPF_ALU32_REG(BPF_ADD, R5, R3),
  1271. BPF_ALU32_REG(BPF_ADD, R5, R4),
  1272. BPF_ALU32_REG(BPF_ADD, R5, R5),
  1273. BPF_ALU32_REG(BPF_ADD, R5, R6),
  1274. BPF_ALU32_REG(BPF_ADD, R5, R7),
  1275. BPF_ALU32_REG(BPF_ADD, R5, R8),
  1276. BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
  1277. BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
  1278. BPF_EXIT_INSN(),
  1279. BPF_ALU32_REG(BPF_ADD, R6, R0),
  1280. BPF_ALU32_REG(BPF_ADD, R6, R1),
  1281. BPF_ALU32_REG(BPF_ADD, R6, R2),
  1282. BPF_ALU32_REG(BPF_ADD, R6, R3),
  1283. BPF_ALU32_REG(BPF_ADD, R6, R4),
  1284. BPF_ALU32_REG(BPF_ADD, R6, R5),
  1285. BPF_ALU32_REG(BPF_ADD, R6, R6),
  1286. BPF_ALU32_REG(BPF_ADD, R6, R7),
  1287. BPF_ALU32_REG(BPF_ADD, R6, R8),
  1288. BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
  1289. BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
  1290. BPF_EXIT_INSN(),
  1291. BPF_ALU32_REG(BPF_ADD, R7, R0),
  1292. BPF_ALU32_REG(BPF_ADD, R7, R1),
  1293. BPF_ALU32_REG(BPF_ADD, R7, R2),
  1294. BPF_ALU32_REG(BPF_ADD, R7, R3),
  1295. BPF_ALU32_REG(BPF_ADD, R7, R4),
  1296. BPF_ALU32_REG(BPF_ADD, R7, R5),
  1297. BPF_ALU32_REG(BPF_ADD, R7, R6),
  1298. BPF_ALU32_REG(BPF_ADD, R7, R7),
  1299. BPF_ALU32_REG(BPF_ADD, R7, R8),
  1300. BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
  1301. BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
  1302. BPF_EXIT_INSN(),
  1303. BPF_ALU32_REG(BPF_ADD, R8, R0),
  1304. BPF_ALU32_REG(BPF_ADD, R8, R1),
  1305. BPF_ALU32_REG(BPF_ADD, R8, R2),
  1306. BPF_ALU32_REG(BPF_ADD, R8, R3),
  1307. BPF_ALU32_REG(BPF_ADD, R8, R4),
  1308. BPF_ALU32_REG(BPF_ADD, R8, R5),
  1309. BPF_ALU32_REG(BPF_ADD, R8, R6),
  1310. BPF_ALU32_REG(BPF_ADD, R8, R7),
  1311. BPF_ALU32_REG(BPF_ADD, R8, R8),
  1312. BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
  1313. BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
  1314. BPF_EXIT_INSN(),
  1315. BPF_ALU32_REG(BPF_ADD, R9, R0),
  1316. BPF_ALU32_REG(BPF_ADD, R9, R1),
  1317. BPF_ALU32_REG(BPF_ADD, R9, R2),
  1318. BPF_ALU32_REG(BPF_ADD, R9, R3),
  1319. BPF_ALU32_REG(BPF_ADD, R9, R4),
  1320. BPF_ALU32_REG(BPF_ADD, R9, R5),
  1321. BPF_ALU32_REG(BPF_ADD, R9, R6),
  1322. BPF_ALU32_REG(BPF_ADD, R9, R7),
  1323. BPF_ALU32_REG(BPF_ADD, R9, R8),
  1324. BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
  1325. BPF_ALU32_REG(BPF_MOV, R0, R9),
  1326. BPF_EXIT_INSN(),
  1327. },
  1328. INTERNAL,
  1329. { },
  1330. { { 0, 2957380 } }
  1331. },
  1332. { /* Mainly checking JIT here. */
  1333. "INT: SUB",
  1334. .u.insns_int = {
  1335. BPF_ALU64_IMM(BPF_MOV, R0, 0),
  1336. BPF_ALU64_IMM(BPF_MOV, R1, 1),
  1337. BPF_ALU64_IMM(BPF_MOV, R2, 2),
  1338. BPF_ALU64_IMM(BPF_MOV, R3, 3),
  1339. BPF_ALU64_IMM(BPF_MOV, R4, 4),
  1340. BPF_ALU64_IMM(BPF_MOV, R5, 5),
  1341. BPF_ALU64_IMM(BPF_MOV, R6, 6),
  1342. BPF_ALU64_IMM(BPF_MOV, R7, 7),
  1343. BPF_ALU64_IMM(BPF_MOV, R8, 8),
  1344. BPF_ALU64_IMM(BPF_MOV, R9, 9),
  1345. BPF_ALU64_REG(BPF_SUB, R0, R0),
  1346. BPF_ALU64_REG(BPF_SUB, R0, R1),
  1347. BPF_ALU64_REG(BPF_SUB, R0, R2),
  1348. BPF_ALU64_REG(BPF_SUB, R0, R3),
  1349. BPF_ALU64_REG(BPF_SUB, R0, R4),
  1350. BPF_ALU64_REG(BPF_SUB, R0, R5),
  1351. BPF_ALU64_REG(BPF_SUB, R0, R6),
  1352. BPF_ALU64_REG(BPF_SUB, R0, R7),
  1353. BPF_ALU64_REG(BPF_SUB, R0, R8),
  1354. BPF_ALU64_REG(BPF_SUB, R0, R9),
  1355. BPF_ALU64_IMM(BPF_SUB, R0, 10),
  1356. BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
  1357. BPF_EXIT_INSN(),
  1358. BPF_ALU64_REG(BPF_SUB, R1, R0),
  1359. BPF_ALU64_REG(BPF_SUB, R1, R2),
  1360. BPF_ALU64_REG(BPF_SUB, R1, R3),
  1361. BPF_ALU64_REG(BPF_SUB, R1, R4),
  1362. BPF_ALU64_REG(BPF_SUB, R1, R5),
  1363. BPF_ALU64_REG(BPF_SUB, R1, R6),
  1364. BPF_ALU64_REG(BPF_SUB, R1, R7),
  1365. BPF_ALU64_REG(BPF_SUB, R1, R8),
  1366. BPF_ALU64_REG(BPF_SUB, R1, R9),
  1367. BPF_ALU64_IMM(BPF_SUB, R1, 10),
  1368. BPF_ALU64_REG(BPF_SUB, R2, R0),
  1369. BPF_ALU64_REG(BPF_SUB, R2, R1),
  1370. BPF_ALU64_REG(BPF_SUB, R2, R3),
  1371. BPF_ALU64_REG(BPF_SUB, R2, R4),
  1372. BPF_ALU64_REG(BPF_SUB, R2, R5),
  1373. BPF_ALU64_REG(BPF_SUB, R2, R6),
  1374. BPF_ALU64_REG(BPF_SUB, R2, R7),
  1375. BPF_ALU64_REG(BPF_SUB, R2, R8),
  1376. BPF_ALU64_REG(BPF_SUB, R2, R9),
  1377. BPF_ALU64_IMM(BPF_SUB, R2, 10),
  1378. BPF_ALU64_REG(BPF_SUB, R3, R0),
  1379. BPF_ALU64_REG(BPF_SUB, R3, R1),
  1380. BPF_ALU64_REG(BPF_SUB, R3, R2),
  1381. BPF_ALU64_REG(BPF_SUB, R3, R4),
  1382. BPF_ALU64_REG(BPF_SUB, R3, R5),
  1383. BPF_ALU64_REG(BPF_SUB, R3, R6),
  1384. BPF_ALU64_REG(BPF_SUB, R3, R7),
  1385. BPF_ALU64_REG(BPF_SUB, R3, R8),
  1386. BPF_ALU64_REG(BPF_SUB, R3, R9),
  1387. BPF_ALU64_IMM(BPF_SUB, R3, 10),
  1388. BPF_ALU64_REG(BPF_SUB, R4, R0),
  1389. BPF_ALU64_REG(BPF_SUB, R4, R1),
  1390. BPF_ALU64_REG(BPF_SUB, R4, R2),
  1391. BPF_ALU64_REG(BPF_SUB, R4, R3),
  1392. BPF_ALU64_REG(BPF_SUB, R4, R5),
  1393. BPF_ALU64_REG(BPF_SUB, R4, R6),
  1394. BPF_ALU64_REG(BPF_SUB, R4, R7),
  1395. BPF_ALU64_REG(BPF_SUB, R4, R8),
  1396. BPF_ALU64_REG(BPF_SUB, R4, R9),
  1397. BPF_ALU64_IMM(BPF_SUB, R4, 10),
  1398. BPF_ALU64_REG(BPF_SUB, R5, R0),
  1399. BPF_ALU64_REG(BPF_SUB, R5, R1),
  1400. BPF_ALU64_REG(BPF_SUB, R5, R2),
  1401. BPF_ALU64_REG(BPF_SUB, R5, R3),
  1402. BPF_ALU64_REG(BPF_SUB, R5, R4),
  1403. BPF_ALU64_REG(BPF_SUB, R5, R6),
  1404. BPF_ALU64_REG(BPF_SUB, R5, R7),
  1405. BPF_ALU64_REG(BPF_SUB, R5, R8),
  1406. BPF_ALU64_REG(BPF_SUB, R5, R9),
  1407. BPF_ALU64_IMM(BPF_SUB, R5, 10),
  1408. BPF_ALU64_REG(BPF_SUB, R6, R0),
  1409. BPF_ALU64_REG(BPF_SUB, R6, R1),
  1410. BPF_ALU64_REG(BPF_SUB, R6, R2),
  1411. BPF_ALU64_REG(BPF_SUB, R6, R3),
  1412. BPF_ALU64_REG(BPF_SUB, R6, R4),
  1413. BPF_ALU64_REG(BPF_SUB, R6, R5),
  1414. BPF_ALU64_REG(BPF_SUB, R6, R7),
  1415. BPF_ALU64_REG(BPF_SUB, R6, R8),
  1416. BPF_ALU64_REG(BPF_SUB, R6, R9),
  1417. BPF_ALU64_IMM(BPF_SUB, R6, 10),
  1418. BPF_ALU64_REG(BPF_SUB, R7, R0),
  1419. BPF_ALU64_REG(BPF_SUB, R7, R1),
  1420. BPF_ALU64_REG(BPF_SUB, R7, R2),
  1421. BPF_ALU64_REG(BPF_SUB, R7, R3),
  1422. BPF_ALU64_REG(BPF_SUB, R7, R4),
  1423. BPF_ALU64_REG(BPF_SUB, R7, R5),
  1424. BPF_ALU64_REG(BPF_SUB, R7, R6),
  1425. BPF_ALU64_REG(BPF_SUB, R7, R8),
  1426. BPF_ALU64_REG(BPF_SUB, R7, R9),
  1427. BPF_ALU64_IMM(BPF_SUB, R7, 10),
  1428. BPF_ALU64_REG(BPF_SUB, R8, R0),
  1429. BPF_ALU64_REG(BPF_SUB, R8, R1),
  1430. BPF_ALU64_REG(BPF_SUB, R8, R2),
  1431. BPF_ALU64_REG(BPF_SUB, R8, R3),
  1432. BPF_ALU64_REG(BPF_SUB, R8, R4),
  1433. BPF_ALU64_REG(BPF_SUB, R8, R5),
  1434. BPF_ALU64_REG(BPF_SUB, R8, R6),
  1435. BPF_ALU64_REG(BPF_SUB, R8, R7),
  1436. BPF_ALU64_REG(BPF_SUB, R8, R9),
  1437. BPF_ALU64_IMM(BPF_SUB, R8, 10),
  1438. BPF_ALU64_REG(BPF_SUB, R9, R0),
  1439. BPF_ALU64_REG(BPF_SUB, R9, R1),
  1440. BPF_ALU64_REG(BPF_SUB, R9, R2),
  1441. BPF_ALU64_REG(BPF_SUB, R9, R3),
  1442. BPF_ALU64_REG(BPF_SUB, R9, R4),
  1443. BPF_ALU64_REG(BPF_SUB, R9, R5),
  1444. BPF_ALU64_REG(BPF_SUB, R9, R6),
  1445. BPF_ALU64_REG(BPF_SUB, R9, R7),
  1446. BPF_ALU64_REG(BPF_SUB, R9, R8),
  1447. BPF_ALU64_IMM(BPF_SUB, R9, 10),
  1448. BPF_ALU64_IMM(BPF_SUB, R0, 10),
  1449. BPF_ALU64_IMM(BPF_NEG, R0, 0),
  1450. BPF_ALU64_REG(BPF_SUB, R0, R1),
  1451. BPF_ALU64_REG(BPF_SUB, R0, R2),
  1452. BPF_ALU64_REG(BPF_SUB, R0, R3),
  1453. BPF_ALU64_REG(BPF_SUB, R0, R4),
  1454. BPF_ALU64_REG(BPF_SUB, R0, R5),
  1455. BPF_ALU64_REG(BPF_SUB, R0, R6),
  1456. BPF_ALU64_REG(BPF_SUB, R0, R7),
  1457. BPF_ALU64_REG(BPF_SUB, R0, R8),
  1458. BPF_ALU64_REG(BPF_SUB, R0, R9),
  1459. BPF_EXIT_INSN(),
  1460. },
  1461. INTERNAL,
  1462. { },
  1463. { { 0, 11 } }
  1464. },
  1465. { /* Mainly checking JIT here. */
  1466. "INT: XOR",
  1467. .u.insns_int = {
  1468. BPF_ALU64_REG(BPF_SUB, R0, R0),
  1469. BPF_ALU64_REG(BPF_XOR, R1, R1),
  1470. BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
  1471. BPF_EXIT_INSN(),
  1472. BPF_ALU64_IMM(BPF_MOV, R0, 10),
  1473. BPF_ALU64_IMM(BPF_MOV, R1, -1),
  1474. BPF_ALU64_REG(BPF_SUB, R1, R1),
  1475. BPF_ALU64_REG(BPF_XOR, R2, R2),
  1476. BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
  1477. BPF_EXIT_INSN(),
  1478. BPF_ALU64_REG(BPF_SUB, R2, R2),
  1479. BPF_ALU64_REG(BPF_XOR, R3, R3),
  1480. BPF_ALU64_IMM(BPF_MOV, R0, 10),
  1481. BPF_ALU64_IMM(BPF_MOV, R1, -1),
  1482. BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
  1483. BPF_EXIT_INSN(),
  1484. BPF_ALU64_REG(BPF_SUB, R3, R3),
  1485. BPF_ALU64_REG(BPF_XOR, R4, R4),
  1486. BPF_ALU64_IMM(BPF_MOV, R2, 1),
  1487. BPF_ALU64_IMM(BPF_MOV, R5, -1),
  1488. BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
  1489. BPF_EXIT_INSN(),
  1490. BPF_ALU64_REG(BPF_SUB, R4, R4),
  1491. BPF_ALU64_REG(BPF_XOR, R5, R5),
  1492. BPF_ALU64_IMM(BPF_MOV, R3, 1),
  1493. BPF_ALU64_IMM(BPF_MOV, R7, -1),
  1494. BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
  1495. BPF_EXIT_INSN(),
  1496. BPF_ALU64_IMM(BPF_MOV, R5, 1),
  1497. BPF_ALU64_REG(BPF_SUB, R5, R5),
  1498. BPF_ALU64_REG(BPF_XOR, R6, R6),
  1499. BPF_ALU64_IMM(BPF_MOV, R1, 1),
  1500. BPF_ALU64_IMM(BPF_MOV, R8, -1),
  1501. BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
  1502. BPF_EXIT_INSN(),
  1503. BPF_ALU64_REG(BPF_SUB, R6, R6),
  1504. BPF_ALU64_REG(BPF_XOR, R7, R7),
  1505. BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
  1506. BPF_EXIT_INSN(),
  1507. BPF_ALU64_REG(BPF_SUB, R7, R7),
  1508. BPF_ALU64_REG(BPF_XOR, R8, R8),
  1509. BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
  1510. BPF_EXIT_INSN(),
  1511. BPF_ALU64_REG(BPF_SUB, R8, R8),
  1512. BPF_ALU64_REG(BPF_XOR, R9, R9),
  1513. BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
  1514. BPF_EXIT_INSN(),
  1515. BPF_ALU64_REG(BPF_SUB, R9, R9),
  1516. BPF_ALU64_REG(BPF_XOR, R0, R0),
  1517. BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
  1518. BPF_EXIT_INSN(),
  1519. BPF_ALU64_REG(BPF_SUB, R1, R1),
  1520. BPF_ALU64_REG(BPF_XOR, R0, R0),
  1521. BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
  1522. BPF_ALU64_IMM(BPF_MOV, R0, 0),
  1523. BPF_EXIT_INSN(),
  1524. BPF_ALU64_IMM(BPF_MOV, R0, 1),
  1525. BPF_EXIT_INSN(),
  1526. },
  1527. INTERNAL,
  1528. { },
  1529. { { 0, 1 } }
  1530. },
  1531. { /* Mainly checking JIT here. */
  1532. "INT: MUL",
  1533. .u.insns_int = {
  1534. BPF_ALU64_IMM(BPF_MOV, R0, 11),
  1535. BPF_ALU64_IMM(BPF_MOV, R1, 1),
  1536. BPF_ALU64_IMM(BPF_MOV, R2, 2),
  1537. BPF_ALU64_IMM(BPF_MOV, R3, 3),
  1538. BPF_ALU64_IMM(BPF_MOV, R4, 4),
  1539. BPF_ALU64_IMM(BPF_MOV, R5, 5),
  1540. BPF_ALU64_IMM(BPF_MOV, R6, 6),
  1541. BPF_ALU64_IMM(BPF_MOV, R7, 7),
  1542. BPF_ALU64_IMM(BPF_MOV, R8, 8),
  1543. BPF_ALU64_IMM(BPF_MOV, R9, 9),
  1544. BPF_ALU64_REG(BPF_MUL, R0, R0),
  1545. BPF_ALU64_REG(BPF_MUL, R0, R1),
  1546. BPF_ALU64_REG(BPF_MUL, R0, R2),
  1547. BPF_ALU64_REG(BPF_MUL, R0, R3),
  1548. BPF_ALU64_REG(BPF_MUL, R0, R4),
  1549. BPF_ALU64_REG(BPF_MUL, R0, R5),
  1550. BPF_ALU64_REG(BPF_MUL, R0, R6),
  1551. BPF_ALU64_REG(BPF_MUL, R0, R7),
  1552. BPF_ALU64_REG(BPF_MUL, R0, R8),
  1553. BPF_ALU64_REG(BPF_MUL, R0, R9),
  1554. BPF_ALU64_IMM(BPF_MUL, R0, 10),
  1555. BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
  1556. BPF_EXIT_INSN(),
  1557. BPF_ALU64_REG(BPF_MUL, R1, R0),
  1558. BPF_ALU64_REG(BPF_MUL, R1, R2),
  1559. BPF_ALU64_REG(BPF_MUL, R1, R3),
  1560. BPF_ALU64_REG(BPF_MUL, R1, R4),
  1561. BPF_ALU64_REG(BPF_MUL, R1, R5),
  1562. BPF_ALU64_REG(BPF_MUL, R1, R6),
  1563. BPF_ALU64_REG(BPF_MUL, R1, R7),
  1564. BPF_ALU64_REG(BPF_MUL, R1, R8),
  1565. BPF_ALU64_REG(BPF_MUL, R1, R9),
  1566. BPF_ALU64_IMM(BPF_MUL, R1, 10),
  1567. BPF_ALU64_REG(BPF_MOV, R2, R1),
  1568. BPF_ALU64_IMM(BPF_RSH, R2, 32),
  1569. BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
  1570. BPF_EXIT_INSN(),
  1571. BPF_ALU64_IMM(BPF_LSH, R1, 32),
  1572. BPF_ALU64_IMM(BPF_ARSH, R1, 32),
  1573. BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
  1574. BPF_EXIT_INSN(),
  1575. BPF_ALU64_REG(BPF_MUL, R2, R0),
  1576. BPF_ALU64_REG(BPF_MUL, R2, R1),
  1577. BPF_ALU64_REG(BPF_MUL, R2, R3),
  1578. BPF_ALU64_REG(BPF_MUL, R2, R4),
  1579. BPF_ALU64_REG(BPF_MUL, R2, R5),
  1580. BPF_ALU64_REG(BPF_MUL, R2, R6),
  1581. BPF_ALU64_REG(BPF_MUL, R2, R7),
  1582. BPF_ALU64_REG(BPF_MUL, R2, R8),
  1583. BPF_ALU64_REG(BPF_MUL, R2, R9),
  1584. BPF_ALU64_IMM(BPF_MUL, R2, 10),
  1585. BPF_ALU64_IMM(BPF_RSH, R2, 32),
  1586. BPF_ALU64_REG(BPF_MOV, R0, R2),
  1587. BPF_EXIT_INSN(),
  1588. },
  1589. INTERNAL,
  1590. { },
  1591. { { 0, 0x35d97ef2 } }
  1592. },
  1593. { /* Mainly checking JIT here. */
  1594. "MOV REG64",
  1595. .u.insns_int = {
  1596. BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
  1597. BPF_MOV64_REG(R1, R0),
  1598. BPF_MOV64_REG(R2, R1),
  1599. BPF_MOV64_REG(R3, R2),
  1600. BPF_MOV64_REG(R4, R3),
  1601. BPF_MOV64_REG(R5, R4),
  1602. BPF_MOV64_REG(R6, R5),
  1603. BPF_MOV64_REG(R7, R6),
  1604. BPF_MOV64_REG(R8, R7),
  1605. BPF_MOV64_REG(R9, R8),
  1606. BPF_ALU64_IMM(BPF_MOV, R0, 0),
  1607. BPF_ALU64_IMM(BPF_MOV, R1, 0),
  1608. BPF_ALU64_IMM(BPF_MOV, R2, 0),
  1609. BPF_ALU64_IMM(BPF_MOV, R3, 0),
  1610. BPF_ALU64_IMM(BPF_MOV, R4, 0),
  1611. BPF_ALU64_IMM(BPF_MOV, R5, 0),
  1612. BPF_ALU64_IMM(BPF_MOV, R6, 0),
  1613. BPF_ALU64_IMM(BPF_MOV, R7, 0),
  1614. BPF_ALU64_IMM(BPF_MOV, R8, 0),
  1615. BPF_ALU64_IMM(BPF_MOV, R9, 0),
  1616. BPF_ALU64_REG(BPF_ADD, R0, R0),
  1617. BPF_ALU64_REG(BPF_ADD, R0, R1),
  1618. BPF_ALU64_REG(BPF_ADD, R0, R2),
  1619. BPF_ALU64_REG(BPF_ADD, R0, R3),
  1620. BPF_ALU64_REG(BPF_ADD, R0, R4),
  1621. BPF_ALU64_REG(BPF_ADD, R0, R5),
  1622. BPF_ALU64_REG(BPF_ADD, R0, R6),
  1623. BPF_ALU64_REG(BPF_ADD, R0, R7),
  1624. BPF_ALU64_REG(BPF_ADD, R0, R8),
  1625. BPF_ALU64_REG(BPF_ADD, R0, R9),
  1626. BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
  1627. BPF_EXIT_INSN(),
  1628. },
  1629. INTERNAL,
  1630. { },
  1631. { { 0, 0xfefe } }
  1632. },
  1633. { /* Mainly checking JIT here. */
  1634. "MOV REG32",
  1635. .u.insns_int = {
  1636. BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
  1637. BPF_MOV64_REG(R1, R0),
  1638. BPF_MOV64_REG(R2, R1),
  1639. BPF_MOV64_REG(R3, R2),
  1640. BPF_MOV64_REG(R4, R3),
  1641. BPF_MOV64_REG(R5, R4),
  1642. BPF_MOV64_REG(R6, R5),
  1643. BPF_MOV64_REG(R7, R6),
  1644. BPF_MOV64_REG(R8, R7),
  1645. BPF_MOV64_REG(R9, R8),
  1646. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  1647. BPF_ALU32_IMM(BPF_MOV, R1, 0),
  1648. BPF_ALU32_IMM(BPF_MOV, R2, 0),
  1649. BPF_ALU32_IMM(BPF_MOV, R3, 0),
  1650. BPF_ALU32_IMM(BPF_MOV, R4, 0),
  1651. BPF_ALU32_IMM(BPF_MOV, R5, 0),
  1652. BPF_ALU32_IMM(BPF_MOV, R6, 0),
  1653. BPF_ALU32_IMM(BPF_MOV, R7, 0),
  1654. BPF_ALU32_IMM(BPF_MOV, R8, 0),
  1655. BPF_ALU32_IMM(BPF_MOV, R9, 0),
  1656. BPF_ALU64_REG(BPF_ADD, R0, R0),
  1657. BPF_ALU64_REG(BPF_ADD, R0, R1),
  1658. BPF_ALU64_REG(BPF_ADD, R0, R2),
  1659. BPF_ALU64_REG(BPF_ADD, R0, R3),
  1660. BPF_ALU64_REG(BPF_ADD, R0, R4),
  1661. BPF_ALU64_REG(BPF_ADD, R0, R5),
  1662. BPF_ALU64_REG(BPF_ADD, R0, R6),
  1663. BPF_ALU64_REG(BPF_ADD, R0, R7),
  1664. BPF_ALU64_REG(BPF_ADD, R0, R8),
  1665. BPF_ALU64_REG(BPF_ADD, R0, R9),
  1666. BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
  1667. BPF_EXIT_INSN(),
  1668. },
  1669. INTERNAL,
  1670. { },
  1671. { { 0, 0xfefe } }
  1672. },
  1673. { /* Mainly checking JIT here. */
  1674. "LD IMM64",
  1675. .u.insns_int = {
  1676. BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
  1677. BPF_MOV64_REG(R1, R0),
  1678. BPF_MOV64_REG(R2, R1),
  1679. BPF_MOV64_REG(R3, R2),
  1680. BPF_MOV64_REG(R4, R3),
  1681. BPF_MOV64_REG(R5, R4),
  1682. BPF_MOV64_REG(R6, R5),
  1683. BPF_MOV64_REG(R7, R6),
  1684. BPF_MOV64_REG(R8, R7),
  1685. BPF_MOV64_REG(R9, R8),
  1686. BPF_LD_IMM64(R0, 0x0LL),
  1687. BPF_LD_IMM64(R1, 0x0LL),
  1688. BPF_LD_IMM64(R2, 0x0LL),
  1689. BPF_LD_IMM64(R3, 0x0LL),
  1690. BPF_LD_IMM64(R4, 0x0LL),
  1691. BPF_LD_IMM64(R5, 0x0LL),
  1692. BPF_LD_IMM64(R6, 0x0LL),
  1693. BPF_LD_IMM64(R7, 0x0LL),
  1694. BPF_LD_IMM64(R8, 0x0LL),
  1695. BPF_LD_IMM64(R9, 0x0LL),
  1696. BPF_ALU64_REG(BPF_ADD, R0, R0),
  1697. BPF_ALU64_REG(BPF_ADD, R0, R1),
  1698. BPF_ALU64_REG(BPF_ADD, R0, R2),
  1699. BPF_ALU64_REG(BPF_ADD, R0, R3),
  1700. BPF_ALU64_REG(BPF_ADD, R0, R4),
  1701. BPF_ALU64_REG(BPF_ADD, R0, R5),
  1702. BPF_ALU64_REG(BPF_ADD, R0, R6),
  1703. BPF_ALU64_REG(BPF_ADD, R0, R7),
  1704. BPF_ALU64_REG(BPF_ADD, R0, R8),
  1705. BPF_ALU64_REG(BPF_ADD, R0, R9),
  1706. BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
  1707. BPF_EXIT_INSN(),
  1708. },
  1709. INTERNAL,
  1710. { },
  1711. { { 0, 0xfefe } }
  1712. },
  1713. {
  1714. "INT: ALU MIX",
  1715. .u.insns_int = {
  1716. BPF_ALU64_IMM(BPF_MOV, R0, 11),
  1717. BPF_ALU64_IMM(BPF_ADD, R0, -1),
  1718. BPF_ALU64_IMM(BPF_MOV, R2, 2),
  1719. BPF_ALU64_IMM(BPF_XOR, R2, 3),
  1720. BPF_ALU64_REG(BPF_DIV, R0, R2),
  1721. BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
  1722. BPF_EXIT_INSN(),
  1723. BPF_ALU64_IMM(BPF_MOD, R0, 3),
  1724. BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
  1725. BPF_EXIT_INSN(),
  1726. BPF_ALU64_IMM(BPF_MOV, R0, -1),
  1727. BPF_EXIT_INSN(),
  1728. },
  1729. INTERNAL,
  1730. { },
  1731. { { 0, -1 } }
  1732. },
  1733. {
  1734. "INT: shifts by register",
  1735. .u.insns_int = {
  1736. BPF_MOV64_IMM(R0, -1234),
  1737. BPF_MOV64_IMM(R1, 1),
  1738. BPF_ALU32_REG(BPF_RSH, R0, R1),
  1739. BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
  1740. BPF_EXIT_INSN(),
  1741. BPF_MOV64_IMM(R2, 1),
  1742. BPF_ALU64_REG(BPF_LSH, R0, R2),
  1743. BPF_MOV32_IMM(R4, -1234),
  1744. BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
  1745. BPF_EXIT_INSN(),
  1746. BPF_ALU64_IMM(BPF_AND, R4, 63),
  1747. BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
  1748. BPF_MOV64_IMM(R3, 47),
  1749. BPF_ALU64_REG(BPF_ARSH, R0, R3),
  1750. BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
  1751. BPF_EXIT_INSN(),
  1752. BPF_MOV64_IMM(R2, 1),
  1753. BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
  1754. BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
  1755. BPF_EXIT_INSN(),
  1756. BPF_MOV64_IMM(R4, 4),
  1757. BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
  1758. BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
  1759. BPF_EXIT_INSN(),
  1760. BPF_MOV64_IMM(R4, 5),
  1761. BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
  1762. BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
  1763. BPF_EXIT_INSN(),
  1764. BPF_MOV64_IMM(R0, -1),
  1765. BPF_EXIT_INSN(),
  1766. },
  1767. INTERNAL,
  1768. { },
  1769. { { 0, -1 } }
  1770. },
  1771. {
  1772. "INT: DIV + ABS",
  1773. .u.insns_int = {
  1774. BPF_ALU64_REG(BPF_MOV, R6, R1),
  1775. BPF_LD_ABS(BPF_B, 3),
  1776. BPF_ALU64_IMM(BPF_MOV, R2, 2),
  1777. BPF_ALU32_REG(BPF_DIV, R0, R2),
  1778. BPF_ALU64_REG(BPF_MOV, R8, R0),
  1779. BPF_LD_ABS(BPF_B, 4),
  1780. BPF_ALU64_REG(BPF_ADD, R8, R0),
  1781. BPF_LD_IND(BPF_B, R8, -70),
  1782. BPF_EXIT_INSN(),
  1783. },
  1784. INTERNAL,
  1785. { 10, 20, 30, 40, 50 },
  1786. { { 4, 0 }, { 5, 10 } }
  1787. },
  1788. {
  1789. "INT: DIV by zero",
  1790. .u.insns_int = {
  1791. BPF_ALU64_REG(BPF_MOV, R6, R1),
  1792. BPF_ALU64_IMM(BPF_MOV, R7, 0),
  1793. BPF_LD_ABS(BPF_B, 3),
  1794. BPF_ALU32_REG(BPF_DIV, R0, R7),
  1795. BPF_EXIT_INSN(),
  1796. },
  1797. INTERNAL,
  1798. { 10, 20, 30, 40, 50 },
  1799. { { 3, 0 }, { 4, 0 } }
  1800. },
  1801. {
  1802. "check: missing ret",
  1803. .u.insns = {
  1804. BPF_STMT(BPF_LD | BPF_IMM, 1),
  1805. },
  1806. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  1807. { },
  1808. { },
  1809. .fill_helper = NULL,
  1810. .expected_errcode = -EINVAL,
  1811. },
  1812. {
  1813. "check: div_k_0",
  1814. .u.insns = {
  1815. BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
  1816. BPF_STMT(BPF_RET | BPF_K, 0)
  1817. },
  1818. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  1819. { },
  1820. { },
  1821. .fill_helper = NULL,
  1822. .expected_errcode = -EINVAL,
  1823. },
  1824. {
  1825. "check: unknown insn",
  1826. .u.insns = {
  1827. /* seccomp insn, rejected in socket filter */
  1828. BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
  1829. BPF_STMT(BPF_RET | BPF_K, 0)
  1830. },
  1831. CLASSIC | FLAG_EXPECTED_FAIL,
  1832. { },
  1833. { },
  1834. .fill_helper = NULL,
  1835. .expected_errcode = -EINVAL,
  1836. },
  1837. {
  1838. "check: out of range spill/fill",
  1839. .u.insns = {
  1840. BPF_STMT(BPF_STX, 16),
  1841. BPF_STMT(BPF_RET | BPF_K, 0)
  1842. },
  1843. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  1844. { },
  1845. { },
  1846. .fill_helper = NULL,
  1847. .expected_errcode = -EINVAL,
  1848. },
  1849. {
  1850. "JUMPS + HOLES",
  1851. .u.insns = {
  1852. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1853. BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
  1854. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1855. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1856. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1857. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1858. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1859. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1860. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1861. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1862. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1863. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1864. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1865. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1866. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1867. BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
  1868. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1869. BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
  1870. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1871. BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
  1872. BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
  1873. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1874. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1875. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1876. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1877. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1878. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1879. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1880. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1881. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1882. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1883. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1884. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1885. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1886. BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
  1887. BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
  1888. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1889. BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
  1890. BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
  1891. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1892. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1893. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1894. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1895. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1896. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1897. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1898. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1899. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1900. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1901. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1902. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1903. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1904. BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
  1905. BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
  1906. BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
  1907. BPF_STMT(BPF_RET | BPF_A, 0),
  1908. BPF_STMT(BPF_RET | BPF_A, 0),
  1909. },
  1910. CLASSIC,
  1911. { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
  1912. 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
  1913. 0x08, 0x00,
  1914. 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
  1915. 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
  1916. 0xc0, 0xa8, 0x33, 0x01,
  1917. 0xc0, 0xa8, 0x33, 0x02,
  1918. 0xbb, 0xb6,
  1919. 0xa9, 0xfa,
  1920. 0x00, 0x14, 0x00, 0x00,
  1921. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1922. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1923. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1924. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1925. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1926. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1927. 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
  1928. 0xcc, 0xcc, 0xcc, 0xcc },
  1929. { { 88, 0x001b } }
  1930. },
  1931. {
  1932. "check: RET X",
  1933. .u.insns = {
  1934. BPF_STMT(BPF_RET | BPF_X, 0),
  1935. },
  1936. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  1937. { },
  1938. { },
  1939. .fill_helper = NULL,
  1940. .expected_errcode = -EINVAL,
  1941. },
  1942. {
  1943. "check: LDX + RET X",
  1944. .u.insns = {
  1945. BPF_STMT(BPF_LDX | BPF_IMM, 42),
  1946. BPF_STMT(BPF_RET | BPF_X, 0),
  1947. },
  1948. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  1949. { },
  1950. { },
  1951. .fill_helper = NULL,
  1952. .expected_errcode = -EINVAL,
  1953. },
  1954. { /* Mainly checking JIT here. */
  1955. "M[]: alt STX + LDX",
  1956. .u.insns = {
  1957. BPF_STMT(BPF_LDX | BPF_IMM, 100),
  1958. BPF_STMT(BPF_STX, 0),
  1959. BPF_STMT(BPF_LDX | BPF_MEM, 0),
  1960. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1961. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1962. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1963. BPF_STMT(BPF_STX, 1),
  1964. BPF_STMT(BPF_LDX | BPF_MEM, 1),
  1965. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1966. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1967. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1968. BPF_STMT(BPF_STX, 2),
  1969. BPF_STMT(BPF_LDX | BPF_MEM, 2),
  1970. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1971. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1972. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1973. BPF_STMT(BPF_STX, 3),
  1974. BPF_STMT(BPF_LDX | BPF_MEM, 3),
  1975. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1976. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1977. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1978. BPF_STMT(BPF_STX, 4),
  1979. BPF_STMT(BPF_LDX | BPF_MEM, 4),
  1980. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1981. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1982. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1983. BPF_STMT(BPF_STX, 5),
  1984. BPF_STMT(BPF_LDX | BPF_MEM, 5),
  1985. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1986. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1987. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1988. BPF_STMT(BPF_STX, 6),
  1989. BPF_STMT(BPF_LDX | BPF_MEM, 6),
  1990. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1991. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1992. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1993. BPF_STMT(BPF_STX, 7),
  1994. BPF_STMT(BPF_LDX | BPF_MEM, 7),
  1995. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  1996. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  1997. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  1998. BPF_STMT(BPF_STX, 8),
  1999. BPF_STMT(BPF_LDX | BPF_MEM, 8),
  2000. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2001. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2002. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2003. BPF_STMT(BPF_STX, 9),
  2004. BPF_STMT(BPF_LDX | BPF_MEM, 9),
  2005. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2006. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2007. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2008. BPF_STMT(BPF_STX, 10),
  2009. BPF_STMT(BPF_LDX | BPF_MEM, 10),
  2010. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2011. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2012. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2013. BPF_STMT(BPF_STX, 11),
  2014. BPF_STMT(BPF_LDX | BPF_MEM, 11),
  2015. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2016. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2017. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2018. BPF_STMT(BPF_STX, 12),
  2019. BPF_STMT(BPF_LDX | BPF_MEM, 12),
  2020. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2021. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2022. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2023. BPF_STMT(BPF_STX, 13),
  2024. BPF_STMT(BPF_LDX | BPF_MEM, 13),
  2025. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2026. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2027. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2028. BPF_STMT(BPF_STX, 14),
  2029. BPF_STMT(BPF_LDX | BPF_MEM, 14),
  2030. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2031. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2032. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2033. BPF_STMT(BPF_STX, 15),
  2034. BPF_STMT(BPF_LDX | BPF_MEM, 15),
  2035. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2036. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
  2037. BPF_STMT(BPF_MISC | BPF_TAX, 0),
  2038. BPF_STMT(BPF_RET | BPF_A, 0),
  2039. },
  2040. CLASSIC | FLAG_NO_DATA,
  2041. { },
  2042. { { 0, 116 } },
  2043. },
  2044. { /* Mainly checking JIT here. */
  2045. "M[]: full STX + full LDX",
  2046. .u.insns = {
  2047. BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
  2048. BPF_STMT(BPF_STX, 0),
  2049. BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
  2050. BPF_STMT(BPF_STX, 1),
  2051. BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
  2052. BPF_STMT(BPF_STX, 2),
  2053. BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
  2054. BPF_STMT(BPF_STX, 3),
  2055. BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
  2056. BPF_STMT(BPF_STX, 4),
  2057. BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
  2058. BPF_STMT(BPF_STX, 5),
  2059. BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
  2060. BPF_STMT(BPF_STX, 6),
  2061. BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
  2062. BPF_STMT(BPF_STX, 7),
  2063. BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
  2064. BPF_STMT(BPF_STX, 8),
  2065. BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
  2066. BPF_STMT(BPF_STX, 9),
  2067. BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
  2068. BPF_STMT(BPF_STX, 10),
  2069. BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
  2070. BPF_STMT(BPF_STX, 11),
  2071. BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
  2072. BPF_STMT(BPF_STX, 12),
  2073. BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
  2074. BPF_STMT(BPF_STX, 13),
  2075. BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
  2076. BPF_STMT(BPF_STX, 14),
  2077. BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
  2078. BPF_STMT(BPF_STX, 15),
  2079. BPF_STMT(BPF_LDX | BPF_MEM, 0),
  2080. BPF_STMT(BPF_MISC | BPF_TXA, 0),
  2081. BPF_STMT(BPF_LDX | BPF_MEM, 1),
  2082. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2083. BPF_STMT(BPF_LDX | BPF_MEM, 2),
  2084. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2085. BPF_STMT(BPF_LDX | BPF_MEM, 3),
  2086. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2087. BPF_STMT(BPF_LDX | BPF_MEM, 4),
  2088. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2089. BPF_STMT(BPF_LDX | BPF_MEM, 5),
  2090. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2091. BPF_STMT(BPF_LDX | BPF_MEM, 6),
  2092. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2093. BPF_STMT(BPF_LDX | BPF_MEM, 7),
  2094. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2095. BPF_STMT(BPF_LDX | BPF_MEM, 8),
  2096. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2097. BPF_STMT(BPF_LDX | BPF_MEM, 9),
  2098. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2099. BPF_STMT(BPF_LDX | BPF_MEM, 10),
  2100. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2101. BPF_STMT(BPF_LDX | BPF_MEM, 11),
  2102. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2103. BPF_STMT(BPF_LDX | BPF_MEM, 12),
  2104. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2105. BPF_STMT(BPF_LDX | BPF_MEM, 13),
  2106. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2107. BPF_STMT(BPF_LDX | BPF_MEM, 14),
  2108. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2109. BPF_STMT(BPF_LDX | BPF_MEM, 15),
  2110. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  2111. BPF_STMT(BPF_RET | BPF_A, 0),
  2112. },
  2113. CLASSIC | FLAG_NO_DATA,
  2114. { },
  2115. { { 0, 0x2a5a5e5 } },
  2116. },
  2117. {
  2118. "check: SKF_AD_MAX",
  2119. .u.insns = {
  2120. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  2121. SKF_AD_OFF + SKF_AD_MAX),
  2122. BPF_STMT(BPF_RET | BPF_A, 0),
  2123. },
  2124. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  2125. { },
  2126. { },
  2127. .fill_helper = NULL,
  2128. .expected_errcode = -EINVAL,
  2129. },
  2130. { /* Passes checker but fails during runtime. */
  2131. "LD [SKF_AD_OFF-1]",
  2132. .u.insns = {
  2133. BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
  2134. SKF_AD_OFF - 1),
  2135. BPF_STMT(BPF_RET | BPF_K, 1),
  2136. },
  2137. CLASSIC,
  2138. { },
  2139. { { 1, 0 } },
  2140. },
  2141. {
  2142. "load 64-bit immediate",
  2143. .u.insns_int = {
  2144. BPF_LD_IMM64(R1, 0x567800001234LL),
  2145. BPF_MOV64_REG(R2, R1),
  2146. BPF_MOV64_REG(R3, R2),
  2147. BPF_ALU64_IMM(BPF_RSH, R2, 32),
  2148. BPF_ALU64_IMM(BPF_LSH, R3, 32),
  2149. BPF_ALU64_IMM(BPF_RSH, R3, 32),
  2150. BPF_ALU64_IMM(BPF_MOV, R0, 0),
  2151. BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
  2152. BPF_EXIT_INSN(),
  2153. BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
  2154. BPF_EXIT_INSN(),
  2155. BPF_LD_IMM64(R0, 0x1ffffffffLL),
  2156. BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
  2157. BPF_EXIT_INSN(),
  2158. },
  2159. INTERNAL,
  2160. { },
  2161. { { 0, 1 } }
  2162. },
  2163. {
  2164. "nmap reduced",
  2165. .u.insns_int = {
  2166. BPF_MOV64_REG(R6, R1),
  2167. BPF_LD_ABS(BPF_H, 12),
  2168. BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
  2169. BPF_LD_ABS(BPF_H, 12),
  2170. BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
  2171. BPF_MOV32_IMM(R0, 18),
  2172. BPF_STX_MEM(BPF_W, R10, R0, -64),
  2173. BPF_LDX_MEM(BPF_W, R7, R10, -64),
  2174. BPF_LD_IND(BPF_W, R7, 14),
  2175. BPF_STX_MEM(BPF_W, R10, R0, -60),
  2176. BPF_MOV32_IMM(R0, 280971478),
  2177. BPF_STX_MEM(BPF_W, R10, R0, -56),
  2178. BPF_LDX_MEM(BPF_W, R7, R10, -56),
  2179. BPF_LDX_MEM(BPF_W, R0, R10, -60),
  2180. BPF_ALU32_REG(BPF_SUB, R0, R7),
  2181. BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
  2182. BPF_LD_ABS(BPF_H, 12),
  2183. BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
  2184. BPF_MOV32_IMM(R0, 22),
  2185. BPF_STX_MEM(BPF_W, R10, R0, -56),
  2186. BPF_LDX_MEM(BPF_W, R7, R10, -56),
  2187. BPF_LD_IND(BPF_H, R7, 14),
  2188. BPF_STX_MEM(BPF_W, R10, R0, -52),
  2189. BPF_MOV32_IMM(R0, 17366),
  2190. BPF_STX_MEM(BPF_W, R10, R0, -48),
  2191. BPF_LDX_MEM(BPF_W, R7, R10, -48),
  2192. BPF_LDX_MEM(BPF_W, R0, R10, -52),
  2193. BPF_ALU32_REG(BPF_SUB, R0, R7),
  2194. BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
  2195. BPF_MOV32_IMM(R0, 256),
  2196. BPF_EXIT_INSN(),
  2197. BPF_MOV32_IMM(R0, 0),
  2198. BPF_EXIT_INSN(),
  2199. },
  2200. INTERNAL,
  2201. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
  2202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2203. 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
  2204. { { 38, 256 } }
  2205. },
  2206. /* BPF_ALU | BPF_MOV | BPF_X */
  2207. {
  2208. "ALU_MOV_X: dst = 2",
  2209. .u.insns_int = {
  2210. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  2211. BPF_ALU32_REG(BPF_MOV, R0, R1),
  2212. BPF_EXIT_INSN(),
  2213. },
  2214. INTERNAL,
  2215. { },
  2216. { { 0, 2 } },
  2217. },
  2218. {
  2219. "ALU_MOV_X: dst = 4294967295",
  2220. .u.insns_int = {
  2221. BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
  2222. BPF_ALU32_REG(BPF_MOV, R0, R1),
  2223. BPF_EXIT_INSN(),
  2224. },
  2225. INTERNAL,
  2226. { },
  2227. { { 0, 4294967295U } },
  2228. },
  2229. {
  2230. "ALU64_MOV_X: dst = 2",
  2231. .u.insns_int = {
  2232. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  2233. BPF_ALU64_REG(BPF_MOV, R0, R1),
  2234. BPF_EXIT_INSN(),
  2235. },
  2236. INTERNAL,
  2237. { },
  2238. { { 0, 2 } },
  2239. },
  2240. {
  2241. "ALU64_MOV_X: dst = 4294967295",
  2242. .u.insns_int = {
  2243. BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
  2244. BPF_ALU64_REG(BPF_MOV, R0, R1),
  2245. BPF_EXIT_INSN(),
  2246. },
  2247. INTERNAL,
  2248. { },
  2249. { { 0, 4294967295U } },
  2250. },
  2251. /* BPF_ALU | BPF_MOV | BPF_K */
  2252. {
  2253. "ALU_MOV_K: dst = 2",
  2254. .u.insns_int = {
  2255. BPF_ALU32_IMM(BPF_MOV, R0, 2),
  2256. BPF_EXIT_INSN(),
  2257. },
  2258. INTERNAL,
  2259. { },
  2260. { { 0, 2 } },
  2261. },
  2262. {
  2263. "ALU_MOV_K: dst = 4294967295",
  2264. .u.insns_int = {
  2265. BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
  2266. BPF_EXIT_INSN(),
  2267. },
  2268. INTERNAL,
  2269. { },
  2270. { { 0, 4294967295U } },
  2271. },
  2272. {
  2273. "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
  2274. .u.insns_int = {
  2275. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  2276. BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
  2277. BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
  2278. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2279. BPF_MOV32_IMM(R0, 2),
  2280. BPF_EXIT_INSN(),
  2281. BPF_MOV32_IMM(R0, 1),
  2282. BPF_EXIT_INSN(),
  2283. },
  2284. INTERNAL,
  2285. { },
  2286. { { 0, 0x1 } },
  2287. },
  2288. {
  2289. "ALU64_MOV_K: dst = 2",
  2290. .u.insns_int = {
  2291. BPF_ALU64_IMM(BPF_MOV, R0, 2),
  2292. BPF_EXIT_INSN(),
  2293. },
  2294. INTERNAL,
  2295. { },
  2296. { { 0, 2 } },
  2297. },
  2298. {
  2299. "ALU64_MOV_K: dst = 2147483647",
  2300. .u.insns_int = {
  2301. BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
  2302. BPF_EXIT_INSN(),
  2303. },
  2304. INTERNAL,
  2305. { },
  2306. { { 0, 2147483647 } },
  2307. },
  2308. {
  2309. "ALU64_OR_K: dst = 0x0",
  2310. .u.insns_int = {
  2311. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  2312. BPF_LD_IMM64(R3, 0x0),
  2313. BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
  2314. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2315. BPF_MOV32_IMM(R0, 2),
  2316. BPF_EXIT_INSN(),
  2317. BPF_MOV32_IMM(R0, 1),
  2318. BPF_EXIT_INSN(),
  2319. },
  2320. INTERNAL,
  2321. { },
  2322. { { 0, 0x1 } },
  2323. },
  2324. {
  2325. "ALU64_MOV_K: dst = -1",
  2326. .u.insns_int = {
  2327. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  2328. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  2329. BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
  2330. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2331. BPF_MOV32_IMM(R0, 2),
  2332. BPF_EXIT_INSN(),
  2333. BPF_MOV32_IMM(R0, 1),
  2334. BPF_EXIT_INSN(),
  2335. },
  2336. INTERNAL,
  2337. { },
  2338. { { 0, 0x1 } },
  2339. },
  2340. /* BPF_ALU | BPF_ADD | BPF_X */
  2341. {
  2342. "ALU_ADD_X: 1 + 2 = 3",
  2343. .u.insns_int = {
  2344. BPF_LD_IMM64(R0, 1),
  2345. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  2346. BPF_ALU32_REG(BPF_ADD, R0, R1),
  2347. BPF_EXIT_INSN(),
  2348. },
  2349. INTERNAL,
  2350. { },
  2351. { { 0, 3 } },
  2352. },
  2353. {
  2354. "ALU_ADD_X: 1 + 4294967294 = 4294967295",
  2355. .u.insns_int = {
  2356. BPF_LD_IMM64(R0, 1),
  2357. BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
  2358. BPF_ALU32_REG(BPF_ADD, R0, R1),
  2359. BPF_EXIT_INSN(),
  2360. },
  2361. INTERNAL,
  2362. { },
  2363. { { 0, 4294967295U } },
  2364. },
  2365. {
  2366. "ALU_ADD_X: 2 + 4294967294 = 0",
  2367. .u.insns_int = {
  2368. BPF_LD_IMM64(R0, 2),
  2369. BPF_LD_IMM64(R1, 4294967294U),
  2370. BPF_ALU32_REG(BPF_ADD, R0, R1),
  2371. BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
  2372. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  2373. BPF_EXIT_INSN(),
  2374. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  2375. BPF_EXIT_INSN(),
  2376. },
  2377. INTERNAL,
  2378. { },
  2379. { { 0, 1 } },
  2380. },
  2381. {
  2382. "ALU64_ADD_X: 1 + 2 = 3",
  2383. .u.insns_int = {
  2384. BPF_LD_IMM64(R0, 1),
  2385. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  2386. BPF_ALU64_REG(BPF_ADD, R0, R1),
  2387. BPF_EXIT_INSN(),
  2388. },
  2389. INTERNAL,
  2390. { },
  2391. { { 0, 3 } },
  2392. },
  2393. {
  2394. "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
  2395. .u.insns_int = {
  2396. BPF_LD_IMM64(R0, 1),
  2397. BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
  2398. BPF_ALU64_REG(BPF_ADD, R0, R1),
  2399. BPF_EXIT_INSN(),
  2400. },
  2401. INTERNAL,
  2402. { },
  2403. { { 0, 4294967295U } },
  2404. },
  2405. {
  2406. "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
  2407. .u.insns_int = {
  2408. BPF_LD_IMM64(R0, 2),
  2409. BPF_LD_IMM64(R1, 4294967294U),
  2410. BPF_LD_IMM64(R2, 4294967296ULL),
  2411. BPF_ALU64_REG(BPF_ADD, R0, R1),
  2412. BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
  2413. BPF_MOV32_IMM(R0, 0),
  2414. BPF_EXIT_INSN(),
  2415. BPF_MOV32_IMM(R0, 1),
  2416. BPF_EXIT_INSN(),
  2417. },
  2418. INTERNAL,
  2419. { },
  2420. { { 0, 1 } },
  2421. },
  2422. /* BPF_ALU | BPF_ADD | BPF_K */
  2423. {
  2424. "ALU_ADD_K: 1 + 2 = 3",
  2425. .u.insns_int = {
  2426. BPF_LD_IMM64(R0, 1),
  2427. BPF_ALU32_IMM(BPF_ADD, R0, 2),
  2428. BPF_EXIT_INSN(),
  2429. },
  2430. INTERNAL,
  2431. { },
  2432. { { 0, 3 } },
  2433. },
  2434. {
  2435. "ALU_ADD_K: 3 + 0 = 3",
  2436. .u.insns_int = {
  2437. BPF_LD_IMM64(R0, 3),
  2438. BPF_ALU32_IMM(BPF_ADD, R0, 0),
  2439. BPF_EXIT_INSN(),
  2440. },
  2441. INTERNAL,
  2442. { },
  2443. { { 0, 3 } },
  2444. },
  2445. {
  2446. "ALU_ADD_K: 1 + 4294967294 = 4294967295",
  2447. .u.insns_int = {
  2448. BPF_LD_IMM64(R0, 1),
  2449. BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
  2450. BPF_EXIT_INSN(),
  2451. },
  2452. INTERNAL,
  2453. { },
  2454. { { 0, 4294967295U } },
  2455. },
  2456. {
  2457. "ALU_ADD_K: 4294967294 + 2 = 0",
  2458. .u.insns_int = {
  2459. BPF_LD_IMM64(R0, 4294967294U),
  2460. BPF_ALU32_IMM(BPF_ADD, R0, 2),
  2461. BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
  2462. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  2463. BPF_EXIT_INSN(),
  2464. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  2465. BPF_EXIT_INSN(),
  2466. },
  2467. INTERNAL,
  2468. { },
  2469. { { 0, 1 } },
  2470. },
  2471. {
  2472. "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
  2473. .u.insns_int = {
  2474. BPF_LD_IMM64(R2, 0x0),
  2475. BPF_LD_IMM64(R3, 0x00000000ffffffff),
  2476. BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
  2477. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2478. BPF_MOV32_IMM(R0, 2),
  2479. BPF_EXIT_INSN(),
  2480. BPF_MOV32_IMM(R0, 1),
  2481. BPF_EXIT_INSN(),
  2482. },
  2483. INTERNAL,
  2484. { },
  2485. { { 0, 0x1 } },
  2486. },
  2487. {
  2488. "ALU_ADD_K: 0 + 0xffff = 0xffff",
  2489. .u.insns_int = {
  2490. BPF_LD_IMM64(R2, 0x0),
  2491. BPF_LD_IMM64(R3, 0xffff),
  2492. BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
  2493. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2494. BPF_MOV32_IMM(R0, 2),
  2495. BPF_EXIT_INSN(),
  2496. BPF_MOV32_IMM(R0, 1),
  2497. BPF_EXIT_INSN(),
  2498. },
  2499. INTERNAL,
  2500. { },
  2501. { { 0, 0x1 } },
  2502. },
  2503. {
  2504. "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
  2505. .u.insns_int = {
  2506. BPF_LD_IMM64(R2, 0x0),
  2507. BPF_LD_IMM64(R3, 0x7fffffff),
  2508. BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
  2509. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2510. BPF_MOV32_IMM(R0, 2),
  2511. BPF_EXIT_INSN(),
  2512. BPF_MOV32_IMM(R0, 1),
  2513. BPF_EXIT_INSN(),
  2514. },
  2515. INTERNAL,
  2516. { },
  2517. { { 0, 0x1 } },
  2518. },
  2519. {
  2520. "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
  2521. .u.insns_int = {
  2522. BPF_LD_IMM64(R2, 0x0),
  2523. BPF_LD_IMM64(R3, 0x80000000),
  2524. BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
  2525. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2526. BPF_MOV32_IMM(R0, 2),
  2527. BPF_EXIT_INSN(),
  2528. BPF_MOV32_IMM(R0, 1),
  2529. BPF_EXIT_INSN(),
  2530. },
  2531. INTERNAL,
  2532. { },
  2533. { { 0, 0x1 } },
  2534. },
  2535. {
  2536. "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
  2537. .u.insns_int = {
  2538. BPF_LD_IMM64(R2, 0x0),
  2539. BPF_LD_IMM64(R3, 0x80008000),
  2540. BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
  2541. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2542. BPF_MOV32_IMM(R0, 2),
  2543. BPF_EXIT_INSN(),
  2544. BPF_MOV32_IMM(R0, 1),
  2545. BPF_EXIT_INSN(),
  2546. },
  2547. INTERNAL,
  2548. { },
  2549. { { 0, 0x1 } },
  2550. },
  2551. {
  2552. "ALU64_ADD_K: 1 + 2 = 3",
  2553. .u.insns_int = {
  2554. BPF_LD_IMM64(R0, 1),
  2555. BPF_ALU64_IMM(BPF_ADD, R0, 2),
  2556. BPF_EXIT_INSN(),
  2557. },
  2558. INTERNAL,
  2559. { },
  2560. { { 0, 3 } },
  2561. },
  2562. {
  2563. "ALU64_ADD_K: 3 + 0 = 3",
  2564. .u.insns_int = {
  2565. BPF_LD_IMM64(R0, 3),
  2566. BPF_ALU64_IMM(BPF_ADD, R0, 0),
  2567. BPF_EXIT_INSN(),
  2568. },
  2569. INTERNAL,
  2570. { },
  2571. { { 0, 3 } },
  2572. },
  2573. {
  2574. "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
  2575. .u.insns_int = {
  2576. BPF_LD_IMM64(R0, 1),
  2577. BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
  2578. BPF_EXIT_INSN(),
  2579. },
  2580. INTERNAL,
  2581. { },
  2582. { { 0, 2147483647 } },
  2583. },
  2584. {
  2585. "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
  2586. .u.insns_int = {
  2587. BPF_LD_IMM64(R0, 4294967294U),
  2588. BPF_LD_IMM64(R1, 4294967296ULL),
  2589. BPF_ALU64_IMM(BPF_ADD, R0, 2),
  2590. BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
  2591. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  2592. BPF_EXIT_INSN(),
  2593. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  2594. BPF_EXIT_INSN(),
  2595. },
  2596. INTERNAL,
  2597. { },
  2598. { { 0, 1 } },
  2599. },
  2600. {
  2601. "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
  2602. .u.insns_int = {
  2603. BPF_LD_IMM64(R0, 2147483646),
  2604. BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
  2605. BPF_EXIT_INSN(),
  2606. },
  2607. INTERNAL,
  2608. { },
  2609. { { 0, -1 } },
  2610. },
  2611. {
  2612. "ALU64_ADD_K: 1 + 0 = 1",
  2613. .u.insns_int = {
  2614. BPF_LD_IMM64(R2, 0x1),
  2615. BPF_LD_IMM64(R3, 0x1),
  2616. BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
  2617. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2618. BPF_MOV32_IMM(R0, 2),
  2619. BPF_EXIT_INSN(),
  2620. BPF_MOV32_IMM(R0, 1),
  2621. BPF_EXIT_INSN(),
  2622. },
  2623. INTERNAL,
  2624. { },
  2625. { { 0, 0x1 } },
  2626. },
  2627. {
  2628. "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
  2629. .u.insns_int = {
  2630. BPF_LD_IMM64(R2, 0x0),
  2631. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  2632. BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
  2633. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2634. BPF_MOV32_IMM(R0, 2),
  2635. BPF_EXIT_INSN(),
  2636. BPF_MOV32_IMM(R0, 1),
  2637. BPF_EXIT_INSN(),
  2638. },
  2639. INTERNAL,
  2640. { },
  2641. { { 0, 0x1 } },
  2642. },
  2643. {
  2644. "ALU64_ADD_K: 0 + 0xffff = 0xffff",
  2645. .u.insns_int = {
  2646. BPF_LD_IMM64(R2, 0x0),
  2647. BPF_LD_IMM64(R3, 0xffff),
  2648. BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
  2649. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2650. BPF_MOV32_IMM(R0, 2),
  2651. BPF_EXIT_INSN(),
  2652. BPF_MOV32_IMM(R0, 1),
  2653. BPF_EXIT_INSN(),
  2654. },
  2655. INTERNAL,
  2656. { },
  2657. { { 0, 0x1 } },
  2658. },
  2659. {
  2660. "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
  2661. .u.insns_int = {
  2662. BPF_LD_IMM64(R2, 0x0),
  2663. BPF_LD_IMM64(R3, 0x7fffffff),
  2664. BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
  2665. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2666. BPF_MOV32_IMM(R0, 2),
  2667. BPF_EXIT_INSN(),
  2668. BPF_MOV32_IMM(R0, 1),
  2669. BPF_EXIT_INSN(),
  2670. },
  2671. INTERNAL,
  2672. { },
  2673. { { 0, 0x1 } },
  2674. },
  2675. {
  2676. "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
  2677. .u.insns_int = {
  2678. BPF_LD_IMM64(R2, 0x0),
  2679. BPF_LD_IMM64(R3, 0xffffffff80000000LL),
  2680. BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
  2681. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2682. BPF_MOV32_IMM(R0, 2),
  2683. BPF_EXIT_INSN(),
  2684. BPF_MOV32_IMM(R0, 1),
  2685. BPF_EXIT_INSN(),
  2686. },
  2687. INTERNAL,
  2688. { },
  2689. { { 0, 0x1 } },
  2690. },
  2691. {
  2692. "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
  2693. .u.insns_int = {
  2694. BPF_LD_IMM64(R2, 0x0),
  2695. BPF_LD_IMM64(R3, 0xffffffff80008000LL),
  2696. BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
  2697. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2698. BPF_MOV32_IMM(R0, 2),
  2699. BPF_EXIT_INSN(),
  2700. BPF_MOV32_IMM(R0, 1),
  2701. BPF_EXIT_INSN(),
  2702. },
  2703. INTERNAL,
  2704. { },
  2705. { { 0, 0x1 } },
  2706. },
  2707. /* BPF_ALU | BPF_SUB | BPF_X */
  2708. {
  2709. "ALU_SUB_X: 3 - 1 = 2",
  2710. .u.insns_int = {
  2711. BPF_LD_IMM64(R0, 3),
  2712. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  2713. BPF_ALU32_REG(BPF_SUB, R0, R1),
  2714. BPF_EXIT_INSN(),
  2715. },
  2716. INTERNAL,
  2717. { },
  2718. { { 0, 2 } },
  2719. },
  2720. {
  2721. "ALU_SUB_X: 4294967295 - 4294967294 = 1",
  2722. .u.insns_int = {
  2723. BPF_LD_IMM64(R0, 4294967295U),
  2724. BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
  2725. BPF_ALU32_REG(BPF_SUB, R0, R1),
  2726. BPF_EXIT_INSN(),
  2727. },
  2728. INTERNAL,
  2729. { },
  2730. { { 0, 1 } },
  2731. },
  2732. {
  2733. "ALU64_SUB_X: 3 - 1 = 2",
  2734. .u.insns_int = {
  2735. BPF_LD_IMM64(R0, 3),
  2736. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  2737. BPF_ALU64_REG(BPF_SUB, R0, R1),
  2738. BPF_EXIT_INSN(),
  2739. },
  2740. INTERNAL,
  2741. { },
  2742. { { 0, 2 } },
  2743. },
  2744. {
  2745. "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
  2746. .u.insns_int = {
  2747. BPF_LD_IMM64(R0, 4294967295U),
  2748. BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
  2749. BPF_ALU64_REG(BPF_SUB, R0, R1),
  2750. BPF_EXIT_INSN(),
  2751. },
  2752. INTERNAL,
  2753. { },
  2754. { { 0, 1 } },
  2755. },
  2756. /* BPF_ALU | BPF_SUB | BPF_K */
  2757. {
  2758. "ALU_SUB_K: 3 - 1 = 2",
  2759. .u.insns_int = {
  2760. BPF_LD_IMM64(R0, 3),
  2761. BPF_ALU32_IMM(BPF_SUB, R0, 1),
  2762. BPF_EXIT_INSN(),
  2763. },
  2764. INTERNAL,
  2765. { },
  2766. { { 0, 2 } },
  2767. },
  2768. {
  2769. "ALU_SUB_K: 3 - 0 = 3",
  2770. .u.insns_int = {
  2771. BPF_LD_IMM64(R0, 3),
  2772. BPF_ALU32_IMM(BPF_SUB, R0, 0),
  2773. BPF_EXIT_INSN(),
  2774. },
  2775. INTERNAL,
  2776. { },
  2777. { { 0, 3 } },
  2778. },
  2779. {
  2780. "ALU_SUB_K: 4294967295 - 4294967294 = 1",
  2781. .u.insns_int = {
  2782. BPF_LD_IMM64(R0, 4294967295U),
  2783. BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
  2784. BPF_EXIT_INSN(),
  2785. },
  2786. INTERNAL,
  2787. { },
  2788. { { 0, 1 } },
  2789. },
  2790. {
  2791. "ALU64_SUB_K: 3 - 1 = 2",
  2792. .u.insns_int = {
  2793. BPF_LD_IMM64(R0, 3),
  2794. BPF_ALU64_IMM(BPF_SUB, R0, 1),
  2795. BPF_EXIT_INSN(),
  2796. },
  2797. INTERNAL,
  2798. { },
  2799. { { 0, 2 } },
  2800. },
  2801. {
  2802. "ALU64_SUB_K: 3 - 0 = 3",
  2803. .u.insns_int = {
  2804. BPF_LD_IMM64(R0, 3),
  2805. BPF_ALU64_IMM(BPF_SUB, R0, 0),
  2806. BPF_EXIT_INSN(),
  2807. },
  2808. INTERNAL,
  2809. { },
  2810. { { 0, 3 } },
  2811. },
  2812. {
  2813. "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
  2814. .u.insns_int = {
  2815. BPF_LD_IMM64(R0, 4294967294U),
  2816. BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
  2817. BPF_EXIT_INSN(),
  2818. },
  2819. INTERNAL,
  2820. { },
  2821. { { 0, -1 } },
  2822. },
  2823. {
  2824. "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
  2825. .u.insns_int = {
  2826. BPF_LD_IMM64(R0, 2147483646),
  2827. BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
  2828. BPF_EXIT_INSN(),
  2829. },
  2830. INTERNAL,
  2831. { },
  2832. { { 0, -1 } },
  2833. },
  2834. /* BPF_ALU | BPF_MUL | BPF_X */
  2835. {
  2836. "ALU_MUL_X: 2 * 3 = 6",
  2837. .u.insns_int = {
  2838. BPF_LD_IMM64(R0, 2),
  2839. BPF_ALU32_IMM(BPF_MOV, R1, 3),
  2840. BPF_ALU32_REG(BPF_MUL, R0, R1),
  2841. BPF_EXIT_INSN(),
  2842. },
  2843. INTERNAL,
  2844. { },
  2845. { { 0, 6 } },
  2846. },
  2847. {
  2848. "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
  2849. .u.insns_int = {
  2850. BPF_LD_IMM64(R0, 2),
  2851. BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
  2852. BPF_ALU32_REG(BPF_MUL, R0, R1),
  2853. BPF_EXIT_INSN(),
  2854. },
  2855. INTERNAL,
  2856. { },
  2857. { { 0, 0xFFFFFFF0 } },
  2858. },
  2859. {
  2860. "ALU_MUL_X: -1 * -1 = 1",
  2861. .u.insns_int = {
  2862. BPF_LD_IMM64(R0, -1),
  2863. BPF_ALU32_IMM(BPF_MOV, R1, -1),
  2864. BPF_ALU32_REG(BPF_MUL, R0, R1),
  2865. BPF_EXIT_INSN(),
  2866. },
  2867. INTERNAL,
  2868. { },
  2869. { { 0, 1 } },
  2870. },
  2871. {
  2872. "ALU64_MUL_X: 2 * 3 = 6",
  2873. .u.insns_int = {
  2874. BPF_LD_IMM64(R0, 2),
  2875. BPF_ALU32_IMM(BPF_MOV, R1, 3),
  2876. BPF_ALU64_REG(BPF_MUL, R0, R1),
  2877. BPF_EXIT_INSN(),
  2878. },
  2879. INTERNAL,
  2880. { },
  2881. { { 0, 6 } },
  2882. },
  2883. {
  2884. "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
  2885. .u.insns_int = {
  2886. BPF_LD_IMM64(R0, 1),
  2887. BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
  2888. BPF_ALU64_REG(BPF_MUL, R0, R1),
  2889. BPF_EXIT_INSN(),
  2890. },
  2891. INTERNAL,
  2892. { },
  2893. { { 0, 2147483647 } },
  2894. },
  2895. /* BPF_ALU | BPF_MUL | BPF_K */
  2896. {
  2897. "ALU_MUL_K: 2 * 3 = 6",
  2898. .u.insns_int = {
  2899. BPF_LD_IMM64(R0, 2),
  2900. BPF_ALU32_IMM(BPF_MUL, R0, 3),
  2901. BPF_EXIT_INSN(),
  2902. },
  2903. INTERNAL,
  2904. { },
  2905. { { 0, 6 } },
  2906. },
  2907. {
  2908. "ALU_MUL_K: 3 * 1 = 3",
  2909. .u.insns_int = {
  2910. BPF_LD_IMM64(R0, 3),
  2911. BPF_ALU32_IMM(BPF_MUL, R0, 1),
  2912. BPF_EXIT_INSN(),
  2913. },
  2914. INTERNAL,
  2915. { },
  2916. { { 0, 3 } },
  2917. },
  2918. {
  2919. "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
  2920. .u.insns_int = {
  2921. BPF_LD_IMM64(R0, 2),
  2922. BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
  2923. BPF_EXIT_INSN(),
  2924. },
  2925. INTERNAL,
  2926. { },
  2927. { { 0, 0xFFFFFFF0 } },
  2928. },
  2929. {
  2930. "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
  2931. .u.insns_int = {
  2932. BPF_LD_IMM64(R2, 0x1),
  2933. BPF_LD_IMM64(R3, 0x00000000ffffffff),
  2934. BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
  2935. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2936. BPF_MOV32_IMM(R0, 2),
  2937. BPF_EXIT_INSN(),
  2938. BPF_MOV32_IMM(R0, 1),
  2939. BPF_EXIT_INSN(),
  2940. },
  2941. INTERNAL,
  2942. { },
  2943. { { 0, 0x1 } },
  2944. },
  2945. {
  2946. "ALU64_MUL_K: 2 * 3 = 6",
  2947. .u.insns_int = {
  2948. BPF_LD_IMM64(R0, 2),
  2949. BPF_ALU64_IMM(BPF_MUL, R0, 3),
  2950. BPF_EXIT_INSN(),
  2951. },
  2952. INTERNAL,
  2953. { },
  2954. { { 0, 6 } },
  2955. },
  2956. {
  2957. "ALU64_MUL_K: 3 * 1 = 3",
  2958. .u.insns_int = {
  2959. BPF_LD_IMM64(R0, 3),
  2960. BPF_ALU64_IMM(BPF_MUL, R0, 1),
  2961. BPF_EXIT_INSN(),
  2962. },
  2963. INTERNAL,
  2964. { },
  2965. { { 0, 3 } },
  2966. },
  2967. {
  2968. "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
  2969. .u.insns_int = {
  2970. BPF_LD_IMM64(R0, 1),
  2971. BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
  2972. BPF_EXIT_INSN(),
  2973. },
  2974. INTERNAL,
  2975. { },
  2976. { { 0, 2147483647 } },
  2977. },
  2978. {
  2979. "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
  2980. .u.insns_int = {
  2981. BPF_LD_IMM64(R0, 1),
  2982. BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
  2983. BPF_EXIT_INSN(),
  2984. },
  2985. INTERNAL,
  2986. { },
  2987. { { 0, -2147483647 } },
  2988. },
  2989. {
  2990. "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
  2991. .u.insns_int = {
  2992. BPF_LD_IMM64(R2, 0x1),
  2993. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  2994. BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
  2995. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  2996. BPF_MOV32_IMM(R0, 2),
  2997. BPF_EXIT_INSN(),
  2998. BPF_MOV32_IMM(R0, 1),
  2999. BPF_EXIT_INSN(),
  3000. },
  3001. INTERNAL,
  3002. { },
  3003. { { 0, 0x1 } },
  3004. },
  3005. /* BPF_ALU | BPF_DIV | BPF_X */
  3006. {
  3007. "ALU_DIV_X: 6 / 2 = 3",
  3008. .u.insns_int = {
  3009. BPF_LD_IMM64(R0, 6),
  3010. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3011. BPF_ALU32_REG(BPF_DIV, R0, R1),
  3012. BPF_EXIT_INSN(),
  3013. },
  3014. INTERNAL,
  3015. { },
  3016. { { 0, 3 } },
  3017. },
  3018. {
  3019. "ALU_DIV_X: 4294967295 / 4294967295 = 1",
  3020. .u.insns_int = {
  3021. BPF_LD_IMM64(R0, 4294967295U),
  3022. BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
  3023. BPF_ALU32_REG(BPF_DIV, R0, R1),
  3024. BPF_EXIT_INSN(),
  3025. },
  3026. INTERNAL,
  3027. { },
  3028. { { 0, 1 } },
  3029. },
  3030. {
  3031. "ALU64_DIV_X: 6 / 2 = 3",
  3032. .u.insns_int = {
  3033. BPF_LD_IMM64(R0, 6),
  3034. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3035. BPF_ALU64_REG(BPF_DIV, R0, R1),
  3036. BPF_EXIT_INSN(),
  3037. },
  3038. INTERNAL,
  3039. { },
  3040. { { 0, 3 } },
  3041. },
  3042. {
  3043. "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
  3044. .u.insns_int = {
  3045. BPF_LD_IMM64(R0, 2147483647),
  3046. BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
  3047. BPF_ALU64_REG(BPF_DIV, R0, R1),
  3048. BPF_EXIT_INSN(),
  3049. },
  3050. INTERNAL,
  3051. { },
  3052. { { 0, 1 } },
  3053. },
  3054. {
  3055. "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
  3056. .u.insns_int = {
  3057. BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
  3058. BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
  3059. BPF_LD_IMM64(R3, 0x0000000000000001LL),
  3060. BPF_ALU64_REG(BPF_DIV, R2, R4),
  3061. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3062. BPF_MOV32_IMM(R0, 2),
  3063. BPF_EXIT_INSN(),
  3064. BPF_MOV32_IMM(R0, 1),
  3065. BPF_EXIT_INSN(),
  3066. },
  3067. INTERNAL,
  3068. { },
  3069. { { 0, 0x1 } },
  3070. },
  3071. /* BPF_ALU | BPF_DIV | BPF_K */
  3072. {
  3073. "ALU_DIV_K: 6 / 2 = 3",
  3074. .u.insns_int = {
  3075. BPF_LD_IMM64(R0, 6),
  3076. BPF_ALU32_IMM(BPF_DIV, R0, 2),
  3077. BPF_EXIT_INSN(),
  3078. },
  3079. INTERNAL,
  3080. { },
  3081. { { 0, 3 } },
  3082. },
  3083. {
  3084. "ALU_DIV_K: 3 / 1 = 3",
  3085. .u.insns_int = {
  3086. BPF_LD_IMM64(R0, 3),
  3087. BPF_ALU32_IMM(BPF_DIV, R0, 1),
  3088. BPF_EXIT_INSN(),
  3089. },
  3090. INTERNAL,
  3091. { },
  3092. { { 0, 3 } },
  3093. },
  3094. {
  3095. "ALU_DIV_K: 4294967295 / 4294967295 = 1",
  3096. .u.insns_int = {
  3097. BPF_LD_IMM64(R0, 4294967295U),
  3098. BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
  3099. BPF_EXIT_INSN(),
  3100. },
  3101. INTERNAL,
  3102. { },
  3103. { { 0, 1 } },
  3104. },
  3105. {
  3106. "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
  3107. .u.insns_int = {
  3108. BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
  3109. BPF_LD_IMM64(R3, 0x1UL),
  3110. BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
  3111. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3112. BPF_MOV32_IMM(R0, 2),
  3113. BPF_EXIT_INSN(),
  3114. BPF_MOV32_IMM(R0, 1),
  3115. BPF_EXIT_INSN(),
  3116. },
  3117. INTERNAL,
  3118. { },
  3119. { { 0, 0x1 } },
  3120. },
  3121. {
  3122. "ALU64_DIV_K: 6 / 2 = 3",
  3123. .u.insns_int = {
  3124. BPF_LD_IMM64(R0, 6),
  3125. BPF_ALU64_IMM(BPF_DIV, R0, 2),
  3126. BPF_EXIT_INSN(),
  3127. },
  3128. INTERNAL,
  3129. { },
  3130. { { 0, 3 } },
  3131. },
  3132. {
  3133. "ALU64_DIV_K: 3 / 1 = 3",
  3134. .u.insns_int = {
  3135. BPF_LD_IMM64(R0, 3),
  3136. BPF_ALU64_IMM(BPF_DIV, R0, 1),
  3137. BPF_EXIT_INSN(),
  3138. },
  3139. INTERNAL,
  3140. { },
  3141. { { 0, 3 } },
  3142. },
  3143. {
  3144. "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
  3145. .u.insns_int = {
  3146. BPF_LD_IMM64(R0, 2147483647),
  3147. BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
  3148. BPF_EXIT_INSN(),
  3149. },
  3150. INTERNAL,
  3151. { },
  3152. { { 0, 1 } },
  3153. },
  3154. {
  3155. "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
  3156. .u.insns_int = {
  3157. BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
  3158. BPF_LD_IMM64(R3, 0x0000000000000001LL),
  3159. BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
  3160. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3161. BPF_MOV32_IMM(R0, 2),
  3162. BPF_EXIT_INSN(),
  3163. BPF_MOV32_IMM(R0, 1),
  3164. BPF_EXIT_INSN(),
  3165. },
  3166. INTERNAL,
  3167. { },
  3168. { { 0, 0x1 } },
  3169. },
  3170. /* BPF_ALU | BPF_MOD | BPF_X */
  3171. {
  3172. "ALU_MOD_X: 3 % 2 = 1",
  3173. .u.insns_int = {
  3174. BPF_LD_IMM64(R0, 3),
  3175. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3176. BPF_ALU32_REG(BPF_MOD, R0, R1),
  3177. BPF_EXIT_INSN(),
  3178. },
  3179. INTERNAL,
  3180. { },
  3181. { { 0, 1 } },
  3182. },
  3183. {
  3184. "ALU_MOD_X: 4294967295 % 4294967293 = 2",
  3185. .u.insns_int = {
  3186. BPF_LD_IMM64(R0, 4294967295U),
  3187. BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
  3188. BPF_ALU32_REG(BPF_MOD, R0, R1),
  3189. BPF_EXIT_INSN(),
  3190. },
  3191. INTERNAL,
  3192. { },
  3193. { { 0, 2 } },
  3194. },
  3195. {
  3196. "ALU64_MOD_X: 3 % 2 = 1",
  3197. .u.insns_int = {
  3198. BPF_LD_IMM64(R0, 3),
  3199. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3200. BPF_ALU64_REG(BPF_MOD, R0, R1),
  3201. BPF_EXIT_INSN(),
  3202. },
  3203. INTERNAL,
  3204. { },
  3205. { { 0, 1 } },
  3206. },
  3207. {
  3208. "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
  3209. .u.insns_int = {
  3210. BPF_LD_IMM64(R0, 2147483647),
  3211. BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
  3212. BPF_ALU64_REG(BPF_MOD, R0, R1),
  3213. BPF_EXIT_INSN(),
  3214. },
  3215. INTERNAL,
  3216. { },
  3217. { { 0, 2 } },
  3218. },
  3219. /* BPF_ALU | BPF_MOD | BPF_K */
  3220. {
  3221. "ALU_MOD_K: 3 % 2 = 1",
  3222. .u.insns_int = {
  3223. BPF_LD_IMM64(R0, 3),
  3224. BPF_ALU32_IMM(BPF_MOD, R0, 2),
  3225. BPF_EXIT_INSN(),
  3226. },
  3227. INTERNAL,
  3228. { },
  3229. { { 0, 1 } },
  3230. },
  3231. {
  3232. "ALU_MOD_K: 3 % 1 = 0",
  3233. .u.insns_int = {
  3234. BPF_LD_IMM64(R0, 3),
  3235. BPF_ALU32_IMM(BPF_MOD, R0, 1),
  3236. BPF_EXIT_INSN(),
  3237. },
  3238. INTERNAL,
  3239. { },
  3240. { { 0, 0 } },
  3241. },
  3242. {
  3243. "ALU_MOD_K: 4294967295 % 4294967293 = 2",
  3244. .u.insns_int = {
  3245. BPF_LD_IMM64(R0, 4294967295U),
  3246. BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
  3247. BPF_EXIT_INSN(),
  3248. },
  3249. INTERNAL,
  3250. { },
  3251. { { 0, 2 } },
  3252. },
  3253. {
  3254. "ALU64_MOD_K: 3 % 2 = 1",
  3255. .u.insns_int = {
  3256. BPF_LD_IMM64(R0, 3),
  3257. BPF_ALU64_IMM(BPF_MOD, R0, 2),
  3258. BPF_EXIT_INSN(),
  3259. },
  3260. INTERNAL,
  3261. { },
  3262. { { 0, 1 } },
  3263. },
  3264. {
  3265. "ALU64_MOD_K: 3 % 1 = 0",
  3266. .u.insns_int = {
  3267. BPF_LD_IMM64(R0, 3),
  3268. BPF_ALU64_IMM(BPF_MOD, R0, 1),
  3269. BPF_EXIT_INSN(),
  3270. },
  3271. INTERNAL,
  3272. { },
  3273. { { 0, 0 } },
  3274. },
  3275. {
  3276. "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
  3277. .u.insns_int = {
  3278. BPF_LD_IMM64(R0, 2147483647),
  3279. BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
  3280. BPF_EXIT_INSN(),
  3281. },
  3282. INTERNAL,
  3283. { },
  3284. { { 0, 2 } },
  3285. },
  3286. /* BPF_ALU | BPF_AND | BPF_X */
  3287. {
  3288. "ALU_AND_X: 3 & 2 = 2",
  3289. .u.insns_int = {
  3290. BPF_LD_IMM64(R0, 3),
  3291. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3292. BPF_ALU32_REG(BPF_AND, R0, R1),
  3293. BPF_EXIT_INSN(),
  3294. },
  3295. INTERNAL,
  3296. { },
  3297. { { 0, 2 } },
  3298. },
  3299. {
  3300. "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
  3301. .u.insns_int = {
  3302. BPF_LD_IMM64(R0, 0xffffffff),
  3303. BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
  3304. BPF_ALU32_REG(BPF_AND, R0, R1),
  3305. BPF_EXIT_INSN(),
  3306. },
  3307. INTERNAL,
  3308. { },
  3309. { { 0, 0xffffffff } },
  3310. },
  3311. {
  3312. "ALU64_AND_X: 3 & 2 = 2",
  3313. .u.insns_int = {
  3314. BPF_LD_IMM64(R0, 3),
  3315. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3316. BPF_ALU64_REG(BPF_AND, R0, R1),
  3317. BPF_EXIT_INSN(),
  3318. },
  3319. INTERNAL,
  3320. { },
  3321. { { 0, 2 } },
  3322. },
  3323. {
  3324. "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
  3325. .u.insns_int = {
  3326. BPF_LD_IMM64(R0, 0xffffffff),
  3327. BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
  3328. BPF_ALU64_REG(BPF_AND, R0, R1),
  3329. BPF_EXIT_INSN(),
  3330. },
  3331. INTERNAL,
  3332. { },
  3333. { { 0, 0xffffffff } },
  3334. },
  3335. /* BPF_ALU | BPF_AND | BPF_K */
  3336. {
  3337. "ALU_AND_K: 3 & 2 = 2",
  3338. .u.insns_int = {
  3339. BPF_LD_IMM64(R0, 3),
  3340. BPF_ALU32_IMM(BPF_AND, R0, 2),
  3341. BPF_EXIT_INSN(),
  3342. },
  3343. INTERNAL,
  3344. { },
  3345. { { 0, 2 } },
  3346. },
  3347. {
  3348. "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
  3349. .u.insns_int = {
  3350. BPF_LD_IMM64(R0, 0xffffffff),
  3351. BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
  3352. BPF_EXIT_INSN(),
  3353. },
  3354. INTERNAL,
  3355. { },
  3356. { { 0, 0xffffffff } },
  3357. },
  3358. {
  3359. "ALU64_AND_K: 3 & 2 = 2",
  3360. .u.insns_int = {
  3361. BPF_LD_IMM64(R0, 3),
  3362. BPF_ALU64_IMM(BPF_AND, R0, 2),
  3363. BPF_EXIT_INSN(),
  3364. },
  3365. INTERNAL,
  3366. { },
  3367. { { 0, 2 } },
  3368. },
  3369. {
  3370. "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
  3371. .u.insns_int = {
  3372. BPF_LD_IMM64(R0, 0xffffffff),
  3373. BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
  3374. BPF_EXIT_INSN(),
  3375. },
  3376. INTERNAL,
  3377. { },
  3378. { { 0, 0xffffffff } },
  3379. },
  3380. {
  3381. "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
  3382. .u.insns_int = {
  3383. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  3384. BPF_LD_IMM64(R3, 0x0000000000000000LL),
  3385. BPF_ALU64_IMM(BPF_AND, R2, 0x0),
  3386. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3387. BPF_MOV32_IMM(R0, 2),
  3388. BPF_EXIT_INSN(),
  3389. BPF_MOV32_IMM(R0, 1),
  3390. BPF_EXIT_INSN(),
  3391. },
  3392. INTERNAL,
  3393. { },
  3394. { { 0, 0x1 } },
  3395. },
  3396. {
  3397. "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
  3398. .u.insns_int = {
  3399. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  3400. BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
  3401. BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
  3402. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3403. BPF_MOV32_IMM(R0, 2),
  3404. BPF_EXIT_INSN(),
  3405. BPF_MOV32_IMM(R0, 1),
  3406. BPF_EXIT_INSN(),
  3407. },
  3408. INTERNAL,
  3409. { },
  3410. { { 0, 0x1 } },
  3411. },
  3412. {
  3413. "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
  3414. .u.insns_int = {
  3415. BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
  3416. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  3417. BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
  3418. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3419. BPF_MOV32_IMM(R0, 2),
  3420. BPF_EXIT_INSN(),
  3421. BPF_MOV32_IMM(R0, 1),
  3422. BPF_EXIT_INSN(),
  3423. },
  3424. INTERNAL,
  3425. { },
  3426. { { 0, 0x1 } },
  3427. },
  3428. /* BPF_ALU | BPF_OR | BPF_X */
  3429. {
  3430. "ALU_OR_X: 1 | 2 = 3",
  3431. .u.insns_int = {
  3432. BPF_LD_IMM64(R0, 1),
  3433. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3434. BPF_ALU32_REG(BPF_OR, R0, R1),
  3435. BPF_EXIT_INSN(),
  3436. },
  3437. INTERNAL,
  3438. { },
  3439. { { 0, 3 } },
  3440. },
  3441. {
  3442. "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
  3443. .u.insns_int = {
  3444. BPF_LD_IMM64(R0, 0),
  3445. BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
  3446. BPF_ALU32_REG(BPF_OR, R0, R1),
  3447. BPF_EXIT_INSN(),
  3448. },
  3449. INTERNAL,
  3450. { },
  3451. { { 0, 0xffffffff } },
  3452. },
  3453. {
  3454. "ALU64_OR_X: 1 | 2 = 3",
  3455. .u.insns_int = {
  3456. BPF_LD_IMM64(R0, 1),
  3457. BPF_ALU32_IMM(BPF_MOV, R1, 2),
  3458. BPF_ALU64_REG(BPF_OR, R0, R1),
  3459. BPF_EXIT_INSN(),
  3460. },
  3461. INTERNAL,
  3462. { },
  3463. { { 0, 3 } },
  3464. },
  3465. {
  3466. "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
  3467. .u.insns_int = {
  3468. BPF_LD_IMM64(R0, 0),
  3469. BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
  3470. BPF_ALU64_REG(BPF_OR, R0, R1),
  3471. BPF_EXIT_INSN(),
  3472. },
  3473. INTERNAL,
  3474. { },
  3475. { { 0, 0xffffffff } },
  3476. },
  3477. /* BPF_ALU | BPF_OR | BPF_K */
  3478. {
  3479. "ALU_OR_K: 1 | 2 = 3",
  3480. .u.insns_int = {
  3481. BPF_LD_IMM64(R0, 1),
  3482. BPF_ALU32_IMM(BPF_OR, R0, 2),
  3483. BPF_EXIT_INSN(),
  3484. },
  3485. INTERNAL,
  3486. { },
  3487. { { 0, 3 } },
  3488. },
  3489. {
  3490. "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
  3491. .u.insns_int = {
  3492. BPF_LD_IMM64(R0, 0),
  3493. BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
  3494. BPF_EXIT_INSN(),
  3495. },
  3496. INTERNAL,
  3497. { },
  3498. { { 0, 0xffffffff } },
  3499. },
  3500. {
  3501. "ALU64_OR_K: 1 | 2 = 3",
  3502. .u.insns_int = {
  3503. BPF_LD_IMM64(R0, 1),
  3504. BPF_ALU64_IMM(BPF_OR, R0, 2),
  3505. BPF_EXIT_INSN(),
  3506. },
  3507. INTERNAL,
  3508. { },
  3509. { { 0, 3 } },
  3510. },
  3511. {
  3512. "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
  3513. .u.insns_int = {
  3514. BPF_LD_IMM64(R0, 0),
  3515. BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
  3516. BPF_EXIT_INSN(),
  3517. },
  3518. INTERNAL,
  3519. { },
  3520. { { 0, 0xffffffff } },
  3521. },
  3522. {
  3523. "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
  3524. .u.insns_int = {
  3525. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  3526. BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
  3527. BPF_ALU64_IMM(BPF_OR, R2, 0x0),
  3528. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3529. BPF_MOV32_IMM(R0, 2),
  3530. BPF_EXIT_INSN(),
  3531. BPF_MOV32_IMM(R0, 1),
  3532. BPF_EXIT_INSN(),
  3533. },
  3534. INTERNAL,
  3535. { },
  3536. { { 0, 0x1 } },
  3537. },
  3538. {
  3539. "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
  3540. .u.insns_int = {
  3541. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  3542. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  3543. BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
  3544. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3545. BPF_MOV32_IMM(R0, 2),
  3546. BPF_EXIT_INSN(),
  3547. BPF_MOV32_IMM(R0, 1),
  3548. BPF_EXIT_INSN(),
  3549. },
  3550. INTERNAL,
  3551. { },
  3552. { { 0, 0x1 } },
  3553. },
  3554. {
  3555. "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
  3556. .u.insns_int = {
  3557. BPF_LD_IMM64(R2, 0x0000000000000000LL),
  3558. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  3559. BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
  3560. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3561. BPF_MOV32_IMM(R0, 2),
  3562. BPF_EXIT_INSN(),
  3563. BPF_MOV32_IMM(R0, 1),
  3564. BPF_EXIT_INSN(),
  3565. },
  3566. INTERNAL,
  3567. { },
  3568. { { 0, 0x1 } },
  3569. },
  3570. /* BPF_ALU | BPF_XOR | BPF_X */
  3571. {
  3572. "ALU_XOR_X: 5 ^ 6 = 3",
  3573. .u.insns_int = {
  3574. BPF_LD_IMM64(R0, 5),
  3575. BPF_ALU32_IMM(BPF_MOV, R1, 6),
  3576. BPF_ALU32_REG(BPF_XOR, R0, R1),
  3577. BPF_EXIT_INSN(),
  3578. },
  3579. INTERNAL,
  3580. { },
  3581. { { 0, 3 } },
  3582. },
  3583. {
  3584. "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
  3585. .u.insns_int = {
  3586. BPF_LD_IMM64(R0, 1),
  3587. BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
  3588. BPF_ALU32_REG(BPF_XOR, R0, R1),
  3589. BPF_EXIT_INSN(),
  3590. },
  3591. INTERNAL,
  3592. { },
  3593. { { 0, 0xfffffffe } },
  3594. },
  3595. {
  3596. "ALU64_XOR_X: 5 ^ 6 = 3",
  3597. .u.insns_int = {
  3598. BPF_LD_IMM64(R0, 5),
  3599. BPF_ALU32_IMM(BPF_MOV, R1, 6),
  3600. BPF_ALU64_REG(BPF_XOR, R0, R1),
  3601. BPF_EXIT_INSN(),
  3602. },
  3603. INTERNAL,
  3604. { },
  3605. { { 0, 3 } },
  3606. },
  3607. {
  3608. "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
  3609. .u.insns_int = {
  3610. BPF_LD_IMM64(R0, 1),
  3611. BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
  3612. BPF_ALU64_REG(BPF_XOR, R0, R1),
  3613. BPF_EXIT_INSN(),
  3614. },
  3615. INTERNAL,
  3616. { },
  3617. { { 0, 0xfffffffe } },
  3618. },
  3619. /* BPF_ALU | BPF_XOR | BPF_K */
  3620. {
  3621. "ALU_XOR_K: 5 ^ 6 = 3",
  3622. .u.insns_int = {
  3623. BPF_LD_IMM64(R0, 5),
  3624. BPF_ALU32_IMM(BPF_XOR, R0, 6),
  3625. BPF_EXIT_INSN(),
  3626. },
  3627. INTERNAL,
  3628. { },
  3629. { { 0, 3 } },
  3630. },
  3631. {
  3632. "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
  3633. .u.insns_int = {
  3634. BPF_LD_IMM64(R0, 1),
  3635. BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
  3636. BPF_EXIT_INSN(),
  3637. },
  3638. INTERNAL,
  3639. { },
  3640. { { 0, 0xfffffffe } },
  3641. },
  3642. {
  3643. "ALU64_XOR_K: 5 ^ 6 = 3",
  3644. .u.insns_int = {
  3645. BPF_LD_IMM64(R0, 5),
  3646. BPF_ALU64_IMM(BPF_XOR, R0, 6),
  3647. BPF_EXIT_INSN(),
  3648. },
  3649. INTERNAL,
  3650. { },
  3651. { { 0, 3 } },
  3652. },
  3653. {
  3654. "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
  3655. .u.insns_int = {
  3656. BPF_LD_IMM64(R0, 1),
  3657. BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
  3658. BPF_EXIT_INSN(),
  3659. },
  3660. INTERNAL,
  3661. { },
  3662. { { 0, 0xfffffffe } },
  3663. },
  3664. {
  3665. "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
  3666. .u.insns_int = {
  3667. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  3668. BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
  3669. BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
  3670. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3671. BPF_MOV32_IMM(R0, 2),
  3672. BPF_EXIT_INSN(),
  3673. BPF_MOV32_IMM(R0, 1),
  3674. BPF_EXIT_INSN(),
  3675. },
  3676. INTERNAL,
  3677. { },
  3678. { { 0, 0x1 } },
  3679. },
  3680. {
  3681. "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
  3682. .u.insns_int = {
  3683. BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
  3684. BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
  3685. BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
  3686. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3687. BPF_MOV32_IMM(R0, 2),
  3688. BPF_EXIT_INSN(),
  3689. BPF_MOV32_IMM(R0, 1),
  3690. BPF_EXIT_INSN(),
  3691. },
  3692. INTERNAL,
  3693. { },
  3694. { { 0, 0x1 } },
  3695. },
  3696. {
  3697. "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
  3698. .u.insns_int = {
  3699. BPF_LD_IMM64(R2, 0x0000000000000000LL),
  3700. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  3701. BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
  3702. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  3703. BPF_MOV32_IMM(R0, 2),
  3704. BPF_EXIT_INSN(),
  3705. BPF_MOV32_IMM(R0, 1),
  3706. BPF_EXIT_INSN(),
  3707. },
  3708. INTERNAL,
  3709. { },
  3710. { { 0, 0x1 } },
  3711. },
  3712. /* BPF_ALU | BPF_LSH | BPF_X */
  3713. {
  3714. "ALU_LSH_X: 1 << 1 = 2",
  3715. .u.insns_int = {
  3716. BPF_LD_IMM64(R0, 1),
  3717. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  3718. BPF_ALU32_REG(BPF_LSH, R0, R1),
  3719. BPF_EXIT_INSN(),
  3720. },
  3721. INTERNAL,
  3722. { },
  3723. { { 0, 2 } },
  3724. },
  3725. {
  3726. "ALU_LSH_X: 1 << 31 = 0x80000000",
  3727. .u.insns_int = {
  3728. BPF_LD_IMM64(R0, 1),
  3729. BPF_ALU32_IMM(BPF_MOV, R1, 31),
  3730. BPF_ALU32_REG(BPF_LSH, R0, R1),
  3731. BPF_EXIT_INSN(),
  3732. },
  3733. INTERNAL,
  3734. { },
  3735. { { 0, 0x80000000 } },
  3736. },
  3737. {
  3738. "ALU64_LSH_X: 1 << 1 = 2",
  3739. .u.insns_int = {
  3740. BPF_LD_IMM64(R0, 1),
  3741. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  3742. BPF_ALU64_REG(BPF_LSH, R0, R1),
  3743. BPF_EXIT_INSN(),
  3744. },
  3745. INTERNAL,
  3746. { },
  3747. { { 0, 2 } },
  3748. },
  3749. {
  3750. "ALU64_LSH_X: 1 << 31 = 0x80000000",
  3751. .u.insns_int = {
  3752. BPF_LD_IMM64(R0, 1),
  3753. BPF_ALU32_IMM(BPF_MOV, R1, 31),
  3754. BPF_ALU64_REG(BPF_LSH, R0, R1),
  3755. BPF_EXIT_INSN(),
  3756. },
  3757. INTERNAL,
  3758. { },
  3759. { { 0, 0x80000000 } },
  3760. },
  3761. /* BPF_ALU | BPF_LSH | BPF_K */
  3762. {
  3763. "ALU_LSH_K: 1 << 1 = 2",
  3764. .u.insns_int = {
  3765. BPF_LD_IMM64(R0, 1),
  3766. BPF_ALU32_IMM(BPF_LSH, R0, 1),
  3767. BPF_EXIT_INSN(),
  3768. },
  3769. INTERNAL,
  3770. { },
  3771. { { 0, 2 } },
  3772. },
  3773. {
  3774. "ALU_LSH_K: 1 << 31 = 0x80000000",
  3775. .u.insns_int = {
  3776. BPF_LD_IMM64(R0, 1),
  3777. BPF_ALU32_IMM(BPF_LSH, R0, 31),
  3778. BPF_EXIT_INSN(),
  3779. },
  3780. INTERNAL,
  3781. { },
  3782. { { 0, 0x80000000 } },
  3783. },
  3784. {
  3785. "ALU64_LSH_K: 1 << 1 = 2",
  3786. .u.insns_int = {
  3787. BPF_LD_IMM64(R0, 1),
  3788. BPF_ALU64_IMM(BPF_LSH, R0, 1),
  3789. BPF_EXIT_INSN(),
  3790. },
  3791. INTERNAL,
  3792. { },
  3793. { { 0, 2 } },
  3794. },
  3795. {
  3796. "ALU64_LSH_K: 1 << 31 = 0x80000000",
  3797. .u.insns_int = {
  3798. BPF_LD_IMM64(R0, 1),
  3799. BPF_ALU64_IMM(BPF_LSH, R0, 31),
  3800. BPF_EXIT_INSN(),
  3801. },
  3802. INTERNAL,
  3803. { },
  3804. { { 0, 0x80000000 } },
  3805. },
  3806. /* BPF_ALU | BPF_RSH | BPF_X */
  3807. {
  3808. "ALU_RSH_X: 2 >> 1 = 1",
  3809. .u.insns_int = {
  3810. BPF_LD_IMM64(R0, 2),
  3811. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  3812. BPF_ALU32_REG(BPF_RSH, R0, R1),
  3813. BPF_EXIT_INSN(),
  3814. },
  3815. INTERNAL,
  3816. { },
  3817. { { 0, 1 } },
  3818. },
  3819. {
  3820. "ALU_RSH_X: 0x80000000 >> 31 = 1",
  3821. .u.insns_int = {
  3822. BPF_LD_IMM64(R0, 0x80000000),
  3823. BPF_ALU32_IMM(BPF_MOV, R1, 31),
  3824. BPF_ALU32_REG(BPF_RSH, R0, R1),
  3825. BPF_EXIT_INSN(),
  3826. },
  3827. INTERNAL,
  3828. { },
  3829. { { 0, 1 } },
  3830. },
  3831. {
  3832. "ALU64_RSH_X: 2 >> 1 = 1",
  3833. .u.insns_int = {
  3834. BPF_LD_IMM64(R0, 2),
  3835. BPF_ALU32_IMM(BPF_MOV, R1, 1),
  3836. BPF_ALU64_REG(BPF_RSH, R0, R1),
  3837. BPF_EXIT_INSN(),
  3838. },
  3839. INTERNAL,
  3840. { },
  3841. { { 0, 1 } },
  3842. },
  3843. {
  3844. "ALU64_RSH_X: 0x80000000 >> 31 = 1",
  3845. .u.insns_int = {
  3846. BPF_LD_IMM64(R0, 0x80000000),
  3847. BPF_ALU32_IMM(BPF_MOV, R1, 31),
  3848. BPF_ALU64_REG(BPF_RSH, R0, R1),
  3849. BPF_EXIT_INSN(),
  3850. },
  3851. INTERNAL,
  3852. { },
  3853. { { 0, 1 } },
  3854. },
  3855. /* BPF_ALU | BPF_RSH | BPF_K */
  3856. {
  3857. "ALU_RSH_K: 2 >> 1 = 1",
  3858. .u.insns_int = {
  3859. BPF_LD_IMM64(R0, 2),
  3860. BPF_ALU32_IMM(BPF_RSH, R0, 1),
  3861. BPF_EXIT_INSN(),
  3862. },
  3863. INTERNAL,
  3864. { },
  3865. { { 0, 1 } },
  3866. },
  3867. {
  3868. "ALU_RSH_K: 0x80000000 >> 31 = 1",
  3869. .u.insns_int = {
  3870. BPF_LD_IMM64(R0, 0x80000000),
  3871. BPF_ALU32_IMM(BPF_RSH, R0, 31),
  3872. BPF_EXIT_INSN(),
  3873. },
  3874. INTERNAL,
  3875. { },
  3876. { { 0, 1 } },
  3877. },
  3878. {
  3879. "ALU64_RSH_K: 2 >> 1 = 1",
  3880. .u.insns_int = {
  3881. BPF_LD_IMM64(R0, 2),
  3882. BPF_ALU64_IMM(BPF_RSH, R0, 1),
  3883. BPF_EXIT_INSN(),
  3884. },
  3885. INTERNAL,
  3886. { },
  3887. { { 0, 1 } },
  3888. },
  3889. {
  3890. "ALU64_RSH_K: 0x80000000 >> 31 = 1",
  3891. .u.insns_int = {
  3892. BPF_LD_IMM64(R0, 0x80000000),
  3893. BPF_ALU64_IMM(BPF_RSH, R0, 31),
  3894. BPF_EXIT_INSN(),
  3895. },
  3896. INTERNAL,
  3897. { },
  3898. { { 0, 1 } },
  3899. },
  3900. /* BPF_ALU | BPF_ARSH | BPF_X */
  3901. {
  3902. "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
  3903. .u.insns_int = {
  3904. BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
  3905. BPF_ALU32_IMM(BPF_MOV, R1, 40),
  3906. BPF_ALU64_REG(BPF_ARSH, R0, R1),
  3907. BPF_EXIT_INSN(),
  3908. },
  3909. INTERNAL,
  3910. { },
  3911. { { 0, 0xffff00ff } },
  3912. },
  3913. /* BPF_ALU | BPF_ARSH | BPF_K */
  3914. {
  3915. "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
  3916. .u.insns_int = {
  3917. BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
  3918. BPF_ALU64_IMM(BPF_ARSH, R0, 40),
  3919. BPF_EXIT_INSN(),
  3920. },
  3921. INTERNAL,
  3922. { },
  3923. { { 0, 0xffff00ff } },
  3924. },
  3925. /* BPF_ALU | BPF_NEG */
  3926. {
  3927. "ALU_NEG: -(3) = -3",
  3928. .u.insns_int = {
  3929. BPF_ALU32_IMM(BPF_MOV, R0, 3),
  3930. BPF_ALU32_IMM(BPF_NEG, R0, 0),
  3931. BPF_EXIT_INSN(),
  3932. },
  3933. INTERNAL,
  3934. { },
  3935. { { 0, -3 } },
  3936. },
  3937. {
  3938. "ALU_NEG: -(-3) = 3",
  3939. .u.insns_int = {
  3940. BPF_ALU32_IMM(BPF_MOV, R0, -3),
  3941. BPF_ALU32_IMM(BPF_NEG, R0, 0),
  3942. BPF_EXIT_INSN(),
  3943. },
  3944. INTERNAL,
  3945. { },
  3946. { { 0, 3 } },
  3947. },
  3948. {
  3949. "ALU64_NEG: -(3) = -3",
  3950. .u.insns_int = {
  3951. BPF_LD_IMM64(R0, 3),
  3952. BPF_ALU64_IMM(BPF_NEG, R0, 0),
  3953. BPF_EXIT_INSN(),
  3954. },
  3955. INTERNAL,
  3956. { },
  3957. { { 0, -3 } },
  3958. },
  3959. {
  3960. "ALU64_NEG: -(-3) = 3",
  3961. .u.insns_int = {
  3962. BPF_LD_IMM64(R0, -3),
  3963. BPF_ALU64_IMM(BPF_NEG, R0, 0),
  3964. BPF_EXIT_INSN(),
  3965. },
  3966. INTERNAL,
  3967. { },
  3968. { { 0, 3 } },
  3969. },
  3970. /* BPF_ALU | BPF_END | BPF_FROM_BE */
  3971. {
  3972. "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
  3973. .u.insns_int = {
  3974. BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
  3975. BPF_ENDIAN(BPF_FROM_BE, R0, 16),
  3976. BPF_EXIT_INSN(),
  3977. },
  3978. INTERNAL,
  3979. { },
  3980. { { 0, cpu_to_be16(0xcdef) } },
  3981. },
  3982. {
  3983. "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
  3984. .u.insns_int = {
  3985. BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
  3986. BPF_ENDIAN(BPF_FROM_BE, R0, 32),
  3987. BPF_ALU64_REG(BPF_MOV, R1, R0),
  3988. BPF_ALU64_IMM(BPF_RSH, R1, 32),
  3989. BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
  3990. BPF_EXIT_INSN(),
  3991. },
  3992. INTERNAL,
  3993. { },
  3994. { { 0, cpu_to_be32(0x89abcdef) } },
  3995. },
  3996. {
  3997. "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
  3998. .u.insns_int = {
  3999. BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
  4000. BPF_ENDIAN(BPF_FROM_BE, R0, 64),
  4001. BPF_EXIT_INSN(),
  4002. },
  4003. INTERNAL,
  4004. { },
  4005. { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
  4006. },
  4007. /* BPF_ALU | BPF_END | BPF_FROM_LE */
  4008. {
  4009. "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
  4010. .u.insns_int = {
  4011. BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
  4012. BPF_ENDIAN(BPF_FROM_LE, R0, 16),
  4013. BPF_EXIT_INSN(),
  4014. },
  4015. INTERNAL,
  4016. { },
  4017. { { 0, cpu_to_le16(0xcdef) } },
  4018. },
  4019. {
  4020. "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
  4021. .u.insns_int = {
  4022. BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
  4023. BPF_ENDIAN(BPF_FROM_LE, R0, 32),
  4024. BPF_ALU64_REG(BPF_MOV, R1, R0),
  4025. BPF_ALU64_IMM(BPF_RSH, R1, 32),
  4026. BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
  4027. BPF_EXIT_INSN(),
  4028. },
  4029. INTERNAL,
  4030. { },
  4031. { { 0, cpu_to_le32(0x89abcdef) } },
  4032. },
  4033. {
  4034. "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
  4035. .u.insns_int = {
  4036. BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
  4037. BPF_ENDIAN(BPF_FROM_LE, R0, 64),
  4038. BPF_EXIT_INSN(),
  4039. },
  4040. INTERNAL,
  4041. { },
  4042. { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
  4043. },
  4044. /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
  4045. {
  4046. "ST_MEM_B: Store/Load byte: max negative",
  4047. .u.insns_int = {
  4048. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4049. BPF_ST_MEM(BPF_B, R10, -40, 0xff),
  4050. BPF_LDX_MEM(BPF_B, R0, R10, -40),
  4051. BPF_EXIT_INSN(),
  4052. },
  4053. INTERNAL,
  4054. { },
  4055. { { 0, 0xff } },
  4056. },
  4057. {
  4058. "ST_MEM_B: Store/Load byte: max positive",
  4059. .u.insns_int = {
  4060. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4061. BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
  4062. BPF_LDX_MEM(BPF_H, R0, R10, -40),
  4063. BPF_EXIT_INSN(),
  4064. },
  4065. INTERNAL,
  4066. { },
  4067. { { 0, 0x7f } },
  4068. },
  4069. {
  4070. "STX_MEM_B: Store/Load byte: max negative",
  4071. .u.insns_int = {
  4072. BPF_LD_IMM64(R0, 0),
  4073. BPF_LD_IMM64(R1, 0xffLL),
  4074. BPF_STX_MEM(BPF_B, R10, R1, -40),
  4075. BPF_LDX_MEM(BPF_B, R0, R10, -40),
  4076. BPF_EXIT_INSN(),
  4077. },
  4078. INTERNAL,
  4079. { },
  4080. { { 0, 0xff } },
  4081. },
  4082. {
  4083. "ST_MEM_H: Store/Load half word: max negative",
  4084. .u.insns_int = {
  4085. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4086. BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
  4087. BPF_LDX_MEM(BPF_H, R0, R10, -40),
  4088. BPF_EXIT_INSN(),
  4089. },
  4090. INTERNAL,
  4091. { },
  4092. { { 0, 0xffff } },
  4093. },
  4094. {
  4095. "ST_MEM_H: Store/Load half word: max positive",
  4096. .u.insns_int = {
  4097. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4098. BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
  4099. BPF_LDX_MEM(BPF_H, R0, R10, -40),
  4100. BPF_EXIT_INSN(),
  4101. },
  4102. INTERNAL,
  4103. { },
  4104. { { 0, 0x7fff } },
  4105. },
  4106. {
  4107. "STX_MEM_H: Store/Load half word: max negative",
  4108. .u.insns_int = {
  4109. BPF_LD_IMM64(R0, 0),
  4110. BPF_LD_IMM64(R1, 0xffffLL),
  4111. BPF_STX_MEM(BPF_H, R10, R1, -40),
  4112. BPF_LDX_MEM(BPF_H, R0, R10, -40),
  4113. BPF_EXIT_INSN(),
  4114. },
  4115. INTERNAL,
  4116. { },
  4117. { { 0, 0xffff } },
  4118. },
  4119. {
  4120. "ST_MEM_W: Store/Load word: max negative",
  4121. .u.insns_int = {
  4122. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4123. BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
  4124. BPF_LDX_MEM(BPF_W, R0, R10, -40),
  4125. BPF_EXIT_INSN(),
  4126. },
  4127. INTERNAL,
  4128. { },
  4129. { { 0, 0xffffffff } },
  4130. },
  4131. {
  4132. "ST_MEM_W: Store/Load word: max positive",
  4133. .u.insns_int = {
  4134. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4135. BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
  4136. BPF_LDX_MEM(BPF_W, R0, R10, -40),
  4137. BPF_EXIT_INSN(),
  4138. },
  4139. INTERNAL,
  4140. { },
  4141. { { 0, 0x7fffffff } },
  4142. },
  4143. {
  4144. "STX_MEM_W: Store/Load word: max negative",
  4145. .u.insns_int = {
  4146. BPF_LD_IMM64(R0, 0),
  4147. BPF_LD_IMM64(R1, 0xffffffffLL),
  4148. BPF_STX_MEM(BPF_W, R10, R1, -40),
  4149. BPF_LDX_MEM(BPF_W, R0, R10, -40),
  4150. BPF_EXIT_INSN(),
  4151. },
  4152. INTERNAL,
  4153. { },
  4154. { { 0, 0xffffffff } },
  4155. },
  4156. {
  4157. "ST_MEM_DW: Store/Load double word: max negative",
  4158. .u.insns_int = {
  4159. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4160. BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
  4161. BPF_LDX_MEM(BPF_DW, R0, R10, -40),
  4162. BPF_EXIT_INSN(),
  4163. },
  4164. INTERNAL,
  4165. { },
  4166. { { 0, 0xffffffff } },
  4167. },
  4168. {
  4169. "ST_MEM_DW: Store/Load double word: max negative 2",
  4170. .u.insns_int = {
  4171. BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
  4172. BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
  4173. BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
  4174. BPF_LDX_MEM(BPF_DW, R2, R10, -40),
  4175. BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
  4176. BPF_MOV32_IMM(R0, 2),
  4177. BPF_EXIT_INSN(),
  4178. BPF_MOV32_IMM(R0, 1),
  4179. BPF_EXIT_INSN(),
  4180. },
  4181. INTERNAL,
  4182. { },
  4183. { { 0, 0x1 } },
  4184. },
  4185. {
  4186. "ST_MEM_DW: Store/Load double word: max positive",
  4187. .u.insns_int = {
  4188. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4189. BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
  4190. BPF_LDX_MEM(BPF_DW, R0, R10, -40),
  4191. BPF_EXIT_INSN(),
  4192. },
  4193. INTERNAL,
  4194. { },
  4195. { { 0, 0x7fffffff } },
  4196. },
  4197. {
  4198. "STX_MEM_DW: Store/Load double word: max negative",
  4199. .u.insns_int = {
  4200. BPF_LD_IMM64(R0, 0),
  4201. BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
  4202. BPF_STX_MEM(BPF_W, R10, R1, -40),
  4203. BPF_LDX_MEM(BPF_W, R0, R10, -40),
  4204. BPF_EXIT_INSN(),
  4205. },
  4206. INTERNAL,
  4207. { },
  4208. { { 0, 0xffffffff } },
  4209. },
  4210. /* BPF_STX | BPF_XADD | BPF_W/DW */
  4211. {
  4212. "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
  4213. .u.insns_int = {
  4214. BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
  4215. BPF_ST_MEM(BPF_W, R10, -40, 0x10),
  4216. BPF_STX_XADD(BPF_W, R10, R0, -40),
  4217. BPF_LDX_MEM(BPF_W, R0, R10, -40),
  4218. BPF_EXIT_INSN(),
  4219. },
  4220. INTERNAL,
  4221. { },
  4222. { { 0, 0x22 } },
  4223. },
  4224. {
  4225. "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
  4226. .u.insns_int = {
  4227. BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
  4228. BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
  4229. BPF_STX_XADD(BPF_DW, R10, R0, -40),
  4230. BPF_LDX_MEM(BPF_DW, R0, R10, -40),
  4231. BPF_EXIT_INSN(),
  4232. },
  4233. INTERNAL,
  4234. { },
  4235. { { 0, 0x22 } },
  4236. },
  4237. /* BPF_JMP | BPF_EXIT */
  4238. {
  4239. "JMP_EXIT",
  4240. .u.insns_int = {
  4241. BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
  4242. BPF_EXIT_INSN(),
  4243. BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
  4244. },
  4245. INTERNAL,
  4246. { },
  4247. { { 0, 0x4711 } },
  4248. },
  4249. /* BPF_JMP | BPF_JA */
  4250. {
  4251. "JMP_JA: Unconditional jump: if (true) return 1",
  4252. .u.insns_int = {
  4253. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4254. BPF_JMP_IMM(BPF_JA, 0, 0, 1),
  4255. BPF_EXIT_INSN(),
  4256. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4257. BPF_EXIT_INSN(),
  4258. },
  4259. INTERNAL,
  4260. { },
  4261. { { 0, 1 } },
  4262. },
  4263. /* BPF_JMP | BPF_JSGT | BPF_K */
  4264. {
  4265. "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
  4266. .u.insns_int = {
  4267. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4268. BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
  4269. BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
  4270. BPF_EXIT_INSN(),
  4271. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4272. BPF_EXIT_INSN(),
  4273. },
  4274. INTERNAL,
  4275. { },
  4276. { { 0, 1 } },
  4277. },
  4278. {
  4279. "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
  4280. .u.insns_int = {
  4281. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4282. BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
  4283. BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
  4284. BPF_EXIT_INSN(),
  4285. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4286. BPF_EXIT_INSN(),
  4287. },
  4288. INTERNAL,
  4289. { },
  4290. { { 0, 1 } },
  4291. },
  4292. /* BPF_JMP | BPF_JSGE | BPF_K */
  4293. {
  4294. "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
  4295. .u.insns_int = {
  4296. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4297. BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
  4298. BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
  4299. BPF_EXIT_INSN(),
  4300. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4301. BPF_EXIT_INSN(),
  4302. },
  4303. INTERNAL,
  4304. { },
  4305. { { 0, 1 } },
  4306. },
  4307. {
  4308. "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
  4309. .u.insns_int = {
  4310. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4311. BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
  4312. BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
  4313. BPF_EXIT_INSN(),
  4314. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4315. BPF_EXIT_INSN(),
  4316. },
  4317. INTERNAL,
  4318. { },
  4319. { { 0, 1 } },
  4320. },
  4321. /* BPF_JMP | BPF_JGT | BPF_K */
  4322. {
  4323. "JMP_JGT_K: if (3 > 2) return 1",
  4324. .u.insns_int = {
  4325. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4326. BPF_LD_IMM64(R1, 3),
  4327. BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
  4328. BPF_EXIT_INSN(),
  4329. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4330. BPF_EXIT_INSN(),
  4331. },
  4332. INTERNAL,
  4333. { },
  4334. { { 0, 1 } },
  4335. },
  4336. {
  4337. "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
  4338. .u.insns_int = {
  4339. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4340. BPF_LD_IMM64(R1, -1),
  4341. BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
  4342. BPF_EXIT_INSN(),
  4343. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4344. BPF_EXIT_INSN(),
  4345. },
  4346. INTERNAL,
  4347. { },
  4348. { { 0, 1 } },
  4349. },
  4350. /* BPF_JMP | BPF_JGE | BPF_K */
  4351. {
  4352. "JMP_JGE_K: if (3 >= 2) return 1",
  4353. .u.insns_int = {
  4354. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4355. BPF_LD_IMM64(R1, 3),
  4356. BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
  4357. BPF_EXIT_INSN(),
  4358. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4359. BPF_EXIT_INSN(),
  4360. },
  4361. INTERNAL,
  4362. { },
  4363. { { 0, 1 } },
  4364. },
  4365. /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
  4366. {
  4367. "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
  4368. .u.insns_int = {
  4369. BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
  4370. BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
  4371. BPF_EXIT_INSN(),
  4372. BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
  4373. BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
  4374. BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
  4375. BPF_EXIT_INSN(),
  4376. },
  4377. INTERNAL,
  4378. { },
  4379. { { 0, 1 } },
  4380. },
  4381. {
  4382. "JMP_JGE_K: if (3 >= 3) return 1",
  4383. .u.insns_int = {
  4384. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4385. BPF_LD_IMM64(R1, 3),
  4386. BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
  4387. BPF_EXIT_INSN(),
  4388. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4389. BPF_EXIT_INSN(),
  4390. },
  4391. INTERNAL,
  4392. { },
  4393. { { 0, 1 } },
  4394. },
  4395. /* BPF_JMP | BPF_JNE | BPF_K */
  4396. {
  4397. "JMP_JNE_K: if (3 != 2) return 1",
  4398. .u.insns_int = {
  4399. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4400. BPF_LD_IMM64(R1, 3),
  4401. BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
  4402. BPF_EXIT_INSN(),
  4403. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4404. BPF_EXIT_INSN(),
  4405. },
  4406. INTERNAL,
  4407. { },
  4408. { { 0, 1 } },
  4409. },
  4410. /* BPF_JMP | BPF_JEQ | BPF_K */
  4411. {
  4412. "JMP_JEQ_K: if (3 == 3) return 1",
  4413. .u.insns_int = {
  4414. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4415. BPF_LD_IMM64(R1, 3),
  4416. BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
  4417. BPF_EXIT_INSN(),
  4418. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4419. BPF_EXIT_INSN(),
  4420. },
  4421. INTERNAL,
  4422. { },
  4423. { { 0, 1 } },
  4424. },
  4425. /* BPF_JMP | BPF_JSET | BPF_K */
  4426. {
  4427. "JMP_JSET_K: if (0x3 & 0x2) return 1",
  4428. .u.insns_int = {
  4429. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4430. BPF_LD_IMM64(R1, 3),
  4431. BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
  4432. BPF_EXIT_INSN(),
  4433. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4434. BPF_EXIT_INSN(),
  4435. },
  4436. INTERNAL,
  4437. { },
  4438. { { 0, 1 } },
  4439. },
  4440. {
  4441. "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
  4442. .u.insns_int = {
  4443. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4444. BPF_LD_IMM64(R1, 3),
  4445. BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
  4446. BPF_EXIT_INSN(),
  4447. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4448. BPF_EXIT_INSN(),
  4449. },
  4450. INTERNAL,
  4451. { },
  4452. { { 0, 1 } },
  4453. },
  4454. /* BPF_JMP | BPF_JSGT | BPF_X */
  4455. {
  4456. "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
  4457. .u.insns_int = {
  4458. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4459. BPF_LD_IMM64(R1, -1),
  4460. BPF_LD_IMM64(R2, -2),
  4461. BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
  4462. BPF_EXIT_INSN(),
  4463. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4464. BPF_EXIT_INSN(),
  4465. },
  4466. INTERNAL,
  4467. { },
  4468. { { 0, 1 } },
  4469. },
  4470. {
  4471. "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
  4472. .u.insns_int = {
  4473. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4474. BPF_LD_IMM64(R1, -1),
  4475. BPF_LD_IMM64(R2, -1),
  4476. BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
  4477. BPF_EXIT_INSN(),
  4478. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4479. BPF_EXIT_INSN(),
  4480. },
  4481. INTERNAL,
  4482. { },
  4483. { { 0, 1 } },
  4484. },
  4485. /* BPF_JMP | BPF_JSGE | BPF_X */
  4486. {
  4487. "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
  4488. .u.insns_int = {
  4489. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4490. BPF_LD_IMM64(R1, -1),
  4491. BPF_LD_IMM64(R2, -2),
  4492. BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
  4493. BPF_EXIT_INSN(),
  4494. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4495. BPF_EXIT_INSN(),
  4496. },
  4497. INTERNAL,
  4498. { },
  4499. { { 0, 1 } },
  4500. },
  4501. {
  4502. "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
  4503. .u.insns_int = {
  4504. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4505. BPF_LD_IMM64(R1, -1),
  4506. BPF_LD_IMM64(R2, -1),
  4507. BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
  4508. BPF_EXIT_INSN(),
  4509. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4510. BPF_EXIT_INSN(),
  4511. },
  4512. INTERNAL,
  4513. { },
  4514. { { 0, 1 } },
  4515. },
  4516. /* BPF_JMP | BPF_JGT | BPF_X */
  4517. {
  4518. "JMP_JGT_X: if (3 > 2) return 1",
  4519. .u.insns_int = {
  4520. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4521. BPF_LD_IMM64(R1, 3),
  4522. BPF_LD_IMM64(R2, 2),
  4523. BPF_JMP_REG(BPF_JGT, R1, R2, 1),
  4524. BPF_EXIT_INSN(),
  4525. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4526. BPF_EXIT_INSN(),
  4527. },
  4528. INTERNAL,
  4529. { },
  4530. { { 0, 1 } },
  4531. },
  4532. {
  4533. "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
  4534. .u.insns_int = {
  4535. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4536. BPF_LD_IMM64(R1, -1),
  4537. BPF_LD_IMM64(R2, 1),
  4538. BPF_JMP_REG(BPF_JGT, R1, R2, 1),
  4539. BPF_EXIT_INSN(),
  4540. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4541. BPF_EXIT_INSN(),
  4542. },
  4543. INTERNAL,
  4544. { },
  4545. { { 0, 1 } },
  4546. },
  4547. /* BPF_JMP | BPF_JGE | BPF_X */
  4548. {
  4549. "JMP_JGE_X: if (3 >= 2) return 1",
  4550. .u.insns_int = {
  4551. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4552. BPF_LD_IMM64(R1, 3),
  4553. BPF_LD_IMM64(R2, 2),
  4554. BPF_JMP_REG(BPF_JGE, R1, R2, 1),
  4555. BPF_EXIT_INSN(),
  4556. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4557. BPF_EXIT_INSN(),
  4558. },
  4559. INTERNAL,
  4560. { },
  4561. { { 0, 1 } },
  4562. },
  4563. {
  4564. "JMP_JGE_X: if (3 >= 3) return 1",
  4565. .u.insns_int = {
  4566. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4567. BPF_LD_IMM64(R1, 3),
  4568. BPF_LD_IMM64(R2, 3),
  4569. BPF_JMP_REG(BPF_JGE, R1, R2, 1),
  4570. BPF_EXIT_INSN(),
  4571. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4572. BPF_EXIT_INSN(),
  4573. },
  4574. INTERNAL,
  4575. { },
  4576. { { 0, 1 } },
  4577. },
  4578. {
  4579. /* Mainly testing JIT + imm64 here. */
  4580. "JMP_JGE_X: ldimm64 test 1",
  4581. .u.insns_int = {
  4582. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4583. BPF_LD_IMM64(R1, 3),
  4584. BPF_LD_IMM64(R2, 2),
  4585. BPF_JMP_REG(BPF_JGE, R1, R2, 2),
  4586. BPF_LD_IMM64(R0, 0xffffffffffffffffUL),
  4587. BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeUL),
  4588. BPF_EXIT_INSN(),
  4589. },
  4590. INTERNAL,
  4591. { },
  4592. { { 0, 0xeeeeeeeeU } },
  4593. },
  4594. {
  4595. "JMP_JGE_X: ldimm64 test 2",
  4596. .u.insns_int = {
  4597. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4598. BPF_LD_IMM64(R1, 3),
  4599. BPF_LD_IMM64(R2, 2),
  4600. BPF_JMP_REG(BPF_JGE, R1, R2, 0),
  4601. BPF_LD_IMM64(R0, 0xffffffffffffffffUL),
  4602. BPF_EXIT_INSN(),
  4603. },
  4604. INTERNAL,
  4605. { },
  4606. { { 0, 0xffffffffU } },
  4607. },
  4608. {
  4609. "JMP_JGE_X: ldimm64 test 3",
  4610. .u.insns_int = {
  4611. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4612. BPF_LD_IMM64(R1, 3),
  4613. BPF_LD_IMM64(R2, 2),
  4614. BPF_JMP_REG(BPF_JGE, R1, R2, 4),
  4615. BPF_LD_IMM64(R0, 0xffffffffffffffffUL),
  4616. BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeUL),
  4617. BPF_EXIT_INSN(),
  4618. },
  4619. INTERNAL,
  4620. { },
  4621. { { 0, 1 } },
  4622. },
  4623. /* BPF_JMP | BPF_JNE | BPF_X */
  4624. {
  4625. "JMP_JNE_X: if (3 != 2) return 1",
  4626. .u.insns_int = {
  4627. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4628. BPF_LD_IMM64(R1, 3),
  4629. BPF_LD_IMM64(R2, 2),
  4630. BPF_JMP_REG(BPF_JNE, R1, R2, 1),
  4631. BPF_EXIT_INSN(),
  4632. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4633. BPF_EXIT_INSN(),
  4634. },
  4635. INTERNAL,
  4636. { },
  4637. { { 0, 1 } },
  4638. },
  4639. /* BPF_JMP | BPF_JEQ | BPF_X */
  4640. {
  4641. "JMP_JEQ_X: if (3 == 3) return 1",
  4642. .u.insns_int = {
  4643. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4644. BPF_LD_IMM64(R1, 3),
  4645. BPF_LD_IMM64(R2, 3),
  4646. BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
  4647. BPF_EXIT_INSN(),
  4648. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4649. BPF_EXIT_INSN(),
  4650. },
  4651. INTERNAL,
  4652. { },
  4653. { { 0, 1 } },
  4654. },
  4655. /* BPF_JMP | BPF_JSET | BPF_X */
  4656. {
  4657. "JMP_JSET_X: if (0x3 & 0x2) return 1",
  4658. .u.insns_int = {
  4659. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4660. BPF_LD_IMM64(R1, 3),
  4661. BPF_LD_IMM64(R2, 2),
  4662. BPF_JMP_REG(BPF_JSET, R1, R2, 1),
  4663. BPF_EXIT_INSN(),
  4664. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4665. BPF_EXIT_INSN(),
  4666. },
  4667. INTERNAL,
  4668. { },
  4669. { { 0, 1 } },
  4670. },
  4671. {
  4672. "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
  4673. .u.insns_int = {
  4674. BPF_ALU32_IMM(BPF_MOV, R0, 0),
  4675. BPF_LD_IMM64(R1, 3),
  4676. BPF_LD_IMM64(R2, 0xffffffff),
  4677. BPF_JMP_REG(BPF_JSET, R1, R2, 1),
  4678. BPF_EXIT_INSN(),
  4679. BPF_ALU32_IMM(BPF_MOV, R0, 1),
  4680. BPF_EXIT_INSN(),
  4681. },
  4682. INTERNAL,
  4683. { },
  4684. { { 0, 1 } },
  4685. },
  4686. {
  4687. "JMP_JA: Jump, gap, jump, ...",
  4688. { },
  4689. CLASSIC | FLAG_NO_DATA,
  4690. { },
  4691. { { 0, 0xababcbac } },
  4692. .fill_helper = bpf_fill_ja,
  4693. },
  4694. { /* Mainly checking JIT here. */
  4695. "BPF_MAXINSNS: Maximum possible literals",
  4696. { },
  4697. CLASSIC | FLAG_NO_DATA,
  4698. { },
  4699. { { 0, 0xffffffff } },
  4700. .fill_helper = bpf_fill_maxinsns1,
  4701. },
  4702. { /* Mainly checking JIT here. */
  4703. "BPF_MAXINSNS: Single literal",
  4704. { },
  4705. CLASSIC | FLAG_NO_DATA,
  4706. { },
  4707. { { 0, 0xfefefefe } },
  4708. .fill_helper = bpf_fill_maxinsns2,
  4709. },
  4710. { /* Mainly checking JIT here. */
  4711. "BPF_MAXINSNS: Run/add until end",
  4712. { },
  4713. CLASSIC | FLAG_NO_DATA,
  4714. { },
  4715. { { 0, 0x947bf368 } },
  4716. .fill_helper = bpf_fill_maxinsns3,
  4717. },
  4718. {
  4719. "BPF_MAXINSNS: Too many instructions",
  4720. { },
  4721. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  4722. { },
  4723. { },
  4724. .fill_helper = bpf_fill_maxinsns4,
  4725. .expected_errcode = -EINVAL,
  4726. },
  4727. { /* Mainly checking JIT here. */
  4728. "BPF_MAXINSNS: Very long jump",
  4729. { },
  4730. CLASSIC | FLAG_NO_DATA,
  4731. { },
  4732. { { 0, 0xabababab } },
  4733. .fill_helper = bpf_fill_maxinsns5,
  4734. },
  4735. { /* Mainly checking JIT here. */
  4736. "BPF_MAXINSNS: Ctx heavy transformations",
  4737. { },
  4738. CLASSIC,
  4739. { },
  4740. {
  4741. { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
  4742. { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
  4743. },
  4744. .fill_helper = bpf_fill_maxinsns6,
  4745. },
  4746. { /* Mainly checking JIT here. */
  4747. "BPF_MAXINSNS: Call heavy transformations",
  4748. { },
  4749. CLASSIC | FLAG_NO_DATA,
  4750. { },
  4751. { { 1, 0 }, { 10, 0 } },
  4752. .fill_helper = bpf_fill_maxinsns7,
  4753. },
  4754. { /* Mainly checking JIT here. */
  4755. "BPF_MAXINSNS: Jump heavy test",
  4756. { },
  4757. CLASSIC | FLAG_NO_DATA,
  4758. { },
  4759. { { 0, 0xffffffff } },
  4760. .fill_helper = bpf_fill_maxinsns8,
  4761. },
  4762. { /* Mainly checking JIT here. */
  4763. "BPF_MAXINSNS: Very long jump backwards",
  4764. { },
  4765. INTERNAL | FLAG_NO_DATA,
  4766. { },
  4767. { { 0, 0xcbababab } },
  4768. .fill_helper = bpf_fill_maxinsns9,
  4769. },
  4770. { /* Mainly checking JIT here. */
  4771. "BPF_MAXINSNS: Edge hopping nuthouse",
  4772. { },
  4773. INTERNAL | FLAG_NO_DATA,
  4774. { },
  4775. { { 0, 0xabababac } },
  4776. .fill_helper = bpf_fill_maxinsns10,
  4777. },
  4778. {
  4779. "BPF_MAXINSNS: Jump, gap, jump, ...",
  4780. { },
  4781. #ifdef CONFIG_BPF_JIT_ALWAYS_ON
  4782. CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
  4783. #else
  4784. CLASSIC | FLAG_NO_DATA,
  4785. #endif
  4786. { },
  4787. { { 0, 0xababcbac } },
  4788. .fill_helper = bpf_fill_maxinsns11,
  4789. .expected_errcode = -ENOTSUPP,
  4790. },
  4791. {
  4792. "BPF_MAXINSNS: ld_abs+get_processor_id",
  4793. { },
  4794. CLASSIC,
  4795. { },
  4796. { { 1, 0xbee } },
  4797. .fill_helper = bpf_fill_ld_abs_get_processor_id,
  4798. },
  4799. {
  4800. "BPF_MAXINSNS: ld_abs+vlan_push/pop",
  4801. { },
  4802. INTERNAL,
  4803. { 0x34 },
  4804. { { ETH_HLEN, 0xbef } },
  4805. .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
  4806. },
  4807. /*
  4808. * LD_IND / LD_ABS on fragmented SKBs
  4809. */
  4810. {
  4811. "LD_IND byte frag",
  4812. .u.insns = {
  4813. BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
  4814. BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
  4815. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4816. },
  4817. CLASSIC | FLAG_SKB_FRAG,
  4818. { },
  4819. { {0x40, 0x42} },
  4820. .frag_data = {
  4821. 0x42, 0x00, 0x00, 0x00,
  4822. 0x43, 0x44, 0x00, 0x00,
  4823. 0x21, 0x07, 0x19, 0x83,
  4824. },
  4825. },
  4826. {
  4827. "LD_IND halfword frag",
  4828. .u.insns = {
  4829. BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
  4830. BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
  4831. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4832. },
  4833. CLASSIC | FLAG_SKB_FRAG,
  4834. { },
  4835. { {0x40, 0x4344} },
  4836. .frag_data = {
  4837. 0x42, 0x00, 0x00, 0x00,
  4838. 0x43, 0x44, 0x00, 0x00,
  4839. 0x21, 0x07, 0x19, 0x83,
  4840. },
  4841. },
  4842. {
  4843. "LD_IND word frag",
  4844. .u.insns = {
  4845. BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
  4846. BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
  4847. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4848. },
  4849. CLASSIC | FLAG_SKB_FRAG,
  4850. { },
  4851. { {0x40, 0x21071983} },
  4852. .frag_data = {
  4853. 0x42, 0x00, 0x00, 0x00,
  4854. 0x43, 0x44, 0x00, 0x00,
  4855. 0x21, 0x07, 0x19, 0x83,
  4856. },
  4857. },
  4858. {
  4859. "LD_IND halfword mixed head/frag",
  4860. .u.insns = {
  4861. BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
  4862. BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
  4863. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4864. },
  4865. CLASSIC | FLAG_SKB_FRAG,
  4866. { [0x3e] = 0x25, [0x3f] = 0x05, },
  4867. { {0x40, 0x0519} },
  4868. .frag_data = { 0x19, 0x82 },
  4869. },
  4870. {
  4871. "LD_IND word mixed head/frag",
  4872. .u.insns = {
  4873. BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
  4874. BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
  4875. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4876. },
  4877. CLASSIC | FLAG_SKB_FRAG,
  4878. { [0x3e] = 0x25, [0x3f] = 0x05, },
  4879. { {0x40, 0x25051982} },
  4880. .frag_data = { 0x19, 0x82 },
  4881. },
  4882. {
  4883. "LD_ABS byte frag",
  4884. .u.insns = {
  4885. BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
  4886. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4887. },
  4888. CLASSIC | FLAG_SKB_FRAG,
  4889. { },
  4890. { {0x40, 0x42} },
  4891. .frag_data = {
  4892. 0x42, 0x00, 0x00, 0x00,
  4893. 0x43, 0x44, 0x00, 0x00,
  4894. 0x21, 0x07, 0x19, 0x83,
  4895. },
  4896. },
  4897. {
  4898. "LD_ABS halfword frag",
  4899. .u.insns = {
  4900. BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
  4901. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4902. },
  4903. CLASSIC | FLAG_SKB_FRAG,
  4904. { },
  4905. { {0x40, 0x4344} },
  4906. .frag_data = {
  4907. 0x42, 0x00, 0x00, 0x00,
  4908. 0x43, 0x44, 0x00, 0x00,
  4909. 0x21, 0x07, 0x19, 0x83,
  4910. },
  4911. },
  4912. {
  4913. "LD_ABS word frag",
  4914. .u.insns = {
  4915. BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
  4916. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4917. },
  4918. CLASSIC | FLAG_SKB_FRAG,
  4919. { },
  4920. { {0x40, 0x21071983} },
  4921. .frag_data = {
  4922. 0x42, 0x00, 0x00, 0x00,
  4923. 0x43, 0x44, 0x00, 0x00,
  4924. 0x21, 0x07, 0x19, 0x83,
  4925. },
  4926. },
  4927. {
  4928. "LD_ABS halfword mixed head/frag",
  4929. .u.insns = {
  4930. BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
  4931. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4932. },
  4933. CLASSIC | FLAG_SKB_FRAG,
  4934. { [0x3e] = 0x25, [0x3f] = 0x05, },
  4935. { {0x40, 0x0519} },
  4936. .frag_data = { 0x19, 0x82 },
  4937. },
  4938. {
  4939. "LD_ABS word mixed head/frag",
  4940. .u.insns = {
  4941. BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
  4942. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4943. },
  4944. CLASSIC | FLAG_SKB_FRAG,
  4945. { [0x3e] = 0x25, [0x3f] = 0x05, },
  4946. { {0x40, 0x25051982} },
  4947. .frag_data = { 0x19, 0x82 },
  4948. },
  4949. /*
  4950. * LD_IND / LD_ABS on non fragmented SKBs
  4951. */
  4952. {
  4953. /*
  4954. * this tests that the JIT/interpreter correctly resets X
  4955. * before using it in an LD_IND instruction.
  4956. */
  4957. "LD_IND byte default X",
  4958. .u.insns = {
  4959. BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
  4960. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4961. },
  4962. CLASSIC,
  4963. { [0x1] = 0x42 },
  4964. { {0x40, 0x42 } },
  4965. },
  4966. {
  4967. "LD_IND byte positive offset",
  4968. .u.insns = {
  4969. BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
  4970. BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
  4971. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4972. },
  4973. CLASSIC,
  4974. { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
  4975. { {0x40, 0x82 } },
  4976. },
  4977. {
  4978. "LD_IND byte negative offset",
  4979. .u.insns = {
  4980. BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
  4981. BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
  4982. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4983. },
  4984. CLASSIC,
  4985. { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
  4986. { {0x40, 0x05 } },
  4987. },
  4988. {
  4989. "LD_IND halfword positive offset",
  4990. .u.insns = {
  4991. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  4992. BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
  4993. BPF_STMT(BPF_RET | BPF_A, 0x0),
  4994. },
  4995. CLASSIC,
  4996. {
  4997. [0x1c] = 0xaa, [0x1d] = 0x55,
  4998. [0x1e] = 0xbb, [0x1f] = 0x66,
  4999. [0x20] = 0xcc, [0x21] = 0x77,
  5000. [0x22] = 0xdd, [0x23] = 0x88,
  5001. },
  5002. { {0x40, 0xdd88 } },
  5003. },
  5004. {
  5005. "LD_IND halfword negative offset",
  5006. .u.insns = {
  5007. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5008. BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
  5009. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5010. },
  5011. CLASSIC,
  5012. {
  5013. [0x1c] = 0xaa, [0x1d] = 0x55,
  5014. [0x1e] = 0xbb, [0x1f] = 0x66,
  5015. [0x20] = 0xcc, [0x21] = 0x77,
  5016. [0x22] = 0xdd, [0x23] = 0x88,
  5017. },
  5018. { {0x40, 0xbb66 } },
  5019. },
  5020. {
  5021. "LD_IND halfword unaligned",
  5022. .u.insns = {
  5023. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5024. BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
  5025. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5026. },
  5027. CLASSIC,
  5028. {
  5029. [0x1c] = 0xaa, [0x1d] = 0x55,
  5030. [0x1e] = 0xbb, [0x1f] = 0x66,
  5031. [0x20] = 0xcc, [0x21] = 0x77,
  5032. [0x22] = 0xdd, [0x23] = 0x88,
  5033. },
  5034. { {0x40, 0x66cc } },
  5035. },
  5036. {
  5037. "LD_IND word positive offset",
  5038. .u.insns = {
  5039. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5040. BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
  5041. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5042. },
  5043. CLASSIC,
  5044. {
  5045. [0x1c] = 0xaa, [0x1d] = 0x55,
  5046. [0x1e] = 0xbb, [0x1f] = 0x66,
  5047. [0x20] = 0xcc, [0x21] = 0x77,
  5048. [0x22] = 0xdd, [0x23] = 0x88,
  5049. [0x24] = 0xee, [0x25] = 0x99,
  5050. [0x26] = 0xff, [0x27] = 0xaa,
  5051. },
  5052. { {0x40, 0xee99ffaa } },
  5053. },
  5054. {
  5055. "LD_IND word negative offset",
  5056. .u.insns = {
  5057. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5058. BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
  5059. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5060. },
  5061. CLASSIC,
  5062. {
  5063. [0x1c] = 0xaa, [0x1d] = 0x55,
  5064. [0x1e] = 0xbb, [0x1f] = 0x66,
  5065. [0x20] = 0xcc, [0x21] = 0x77,
  5066. [0x22] = 0xdd, [0x23] = 0x88,
  5067. [0x24] = 0xee, [0x25] = 0x99,
  5068. [0x26] = 0xff, [0x27] = 0xaa,
  5069. },
  5070. { {0x40, 0xaa55bb66 } },
  5071. },
  5072. {
  5073. "LD_IND word unaligned (addr & 3 == 2)",
  5074. .u.insns = {
  5075. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5076. BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
  5077. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5078. },
  5079. CLASSIC,
  5080. {
  5081. [0x1c] = 0xaa, [0x1d] = 0x55,
  5082. [0x1e] = 0xbb, [0x1f] = 0x66,
  5083. [0x20] = 0xcc, [0x21] = 0x77,
  5084. [0x22] = 0xdd, [0x23] = 0x88,
  5085. [0x24] = 0xee, [0x25] = 0x99,
  5086. [0x26] = 0xff, [0x27] = 0xaa,
  5087. },
  5088. { {0x40, 0xbb66cc77 } },
  5089. },
  5090. {
  5091. "LD_IND word unaligned (addr & 3 == 1)",
  5092. .u.insns = {
  5093. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5094. BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
  5095. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5096. },
  5097. CLASSIC,
  5098. {
  5099. [0x1c] = 0xaa, [0x1d] = 0x55,
  5100. [0x1e] = 0xbb, [0x1f] = 0x66,
  5101. [0x20] = 0xcc, [0x21] = 0x77,
  5102. [0x22] = 0xdd, [0x23] = 0x88,
  5103. [0x24] = 0xee, [0x25] = 0x99,
  5104. [0x26] = 0xff, [0x27] = 0xaa,
  5105. },
  5106. { {0x40, 0x55bb66cc } },
  5107. },
  5108. {
  5109. "LD_IND word unaligned (addr & 3 == 3)",
  5110. .u.insns = {
  5111. BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
  5112. BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
  5113. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5114. },
  5115. CLASSIC,
  5116. {
  5117. [0x1c] = 0xaa, [0x1d] = 0x55,
  5118. [0x1e] = 0xbb, [0x1f] = 0x66,
  5119. [0x20] = 0xcc, [0x21] = 0x77,
  5120. [0x22] = 0xdd, [0x23] = 0x88,
  5121. [0x24] = 0xee, [0x25] = 0x99,
  5122. [0x26] = 0xff, [0x27] = 0xaa,
  5123. },
  5124. { {0x40, 0x66cc77dd } },
  5125. },
  5126. {
  5127. "LD_ABS byte",
  5128. .u.insns = {
  5129. BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
  5130. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5131. },
  5132. CLASSIC,
  5133. {
  5134. [0x1c] = 0xaa, [0x1d] = 0x55,
  5135. [0x1e] = 0xbb, [0x1f] = 0x66,
  5136. [0x20] = 0xcc, [0x21] = 0x77,
  5137. [0x22] = 0xdd, [0x23] = 0x88,
  5138. [0x24] = 0xee, [0x25] = 0x99,
  5139. [0x26] = 0xff, [0x27] = 0xaa,
  5140. },
  5141. { {0x40, 0xcc } },
  5142. },
  5143. {
  5144. "LD_ABS halfword",
  5145. .u.insns = {
  5146. BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
  5147. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5148. },
  5149. CLASSIC,
  5150. {
  5151. [0x1c] = 0xaa, [0x1d] = 0x55,
  5152. [0x1e] = 0xbb, [0x1f] = 0x66,
  5153. [0x20] = 0xcc, [0x21] = 0x77,
  5154. [0x22] = 0xdd, [0x23] = 0x88,
  5155. [0x24] = 0xee, [0x25] = 0x99,
  5156. [0x26] = 0xff, [0x27] = 0xaa,
  5157. },
  5158. { {0x40, 0xdd88 } },
  5159. },
  5160. {
  5161. "LD_ABS halfword unaligned",
  5162. .u.insns = {
  5163. BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
  5164. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5165. },
  5166. CLASSIC,
  5167. {
  5168. [0x1c] = 0xaa, [0x1d] = 0x55,
  5169. [0x1e] = 0xbb, [0x1f] = 0x66,
  5170. [0x20] = 0xcc, [0x21] = 0x77,
  5171. [0x22] = 0xdd, [0x23] = 0x88,
  5172. [0x24] = 0xee, [0x25] = 0x99,
  5173. [0x26] = 0xff, [0x27] = 0xaa,
  5174. },
  5175. { {0x40, 0x99ff } },
  5176. },
  5177. {
  5178. "LD_ABS word",
  5179. .u.insns = {
  5180. BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
  5181. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5182. },
  5183. CLASSIC,
  5184. {
  5185. [0x1c] = 0xaa, [0x1d] = 0x55,
  5186. [0x1e] = 0xbb, [0x1f] = 0x66,
  5187. [0x20] = 0xcc, [0x21] = 0x77,
  5188. [0x22] = 0xdd, [0x23] = 0x88,
  5189. [0x24] = 0xee, [0x25] = 0x99,
  5190. [0x26] = 0xff, [0x27] = 0xaa,
  5191. },
  5192. { {0x40, 0xaa55bb66 } },
  5193. },
  5194. {
  5195. "LD_ABS word unaligned (addr & 3 == 2)",
  5196. .u.insns = {
  5197. BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
  5198. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5199. },
  5200. CLASSIC,
  5201. {
  5202. [0x1c] = 0xaa, [0x1d] = 0x55,
  5203. [0x1e] = 0xbb, [0x1f] = 0x66,
  5204. [0x20] = 0xcc, [0x21] = 0x77,
  5205. [0x22] = 0xdd, [0x23] = 0x88,
  5206. [0x24] = 0xee, [0x25] = 0x99,
  5207. [0x26] = 0xff, [0x27] = 0xaa,
  5208. },
  5209. { {0x40, 0xdd88ee99 } },
  5210. },
  5211. {
  5212. "LD_ABS word unaligned (addr & 3 == 1)",
  5213. .u.insns = {
  5214. BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
  5215. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5216. },
  5217. CLASSIC,
  5218. {
  5219. [0x1c] = 0xaa, [0x1d] = 0x55,
  5220. [0x1e] = 0xbb, [0x1f] = 0x66,
  5221. [0x20] = 0xcc, [0x21] = 0x77,
  5222. [0x22] = 0xdd, [0x23] = 0x88,
  5223. [0x24] = 0xee, [0x25] = 0x99,
  5224. [0x26] = 0xff, [0x27] = 0xaa,
  5225. },
  5226. { {0x40, 0x77dd88ee } },
  5227. },
  5228. {
  5229. "LD_ABS word unaligned (addr & 3 == 3)",
  5230. .u.insns = {
  5231. BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
  5232. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5233. },
  5234. CLASSIC,
  5235. {
  5236. [0x1c] = 0xaa, [0x1d] = 0x55,
  5237. [0x1e] = 0xbb, [0x1f] = 0x66,
  5238. [0x20] = 0xcc, [0x21] = 0x77,
  5239. [0x22] = 0xdd, [0x23] = 0x88,
  5240. [0x24] = 0xee, [0x25] = 0x99,
  5241. [0x26] = 0xff, [0x27] = 0xaa,
  5242. },
  5243. { {0x40, 0x88ee99ff } },
  5244. },
  5245. /*
  5246. * verify that the interpreter or JIT correctly sets A and X
  5247. * to 0.
  5248. */
  5249. {
  5250. "ADD default X",
  5251. .u.insns = {
  5252. /*
  5253. * A = 0x42
  5254. * A = A + X
  5255. * ret A
  5256. */
  5257. BPF_STMT(BPF_LD | BPF_IMM, 0x42),
  5258. BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
  5259. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5260. },
  5261. CLASSIC | FLAG_NO_DATA,
  5262. {},
  5263. { {0x1, 0x42 } },
  5264. },
  5265. {
  5266. "ADD default A",
  5267. .u.insns = {
  5268. /*
  5269. * A = A + 0x42
  5270. * ret A
  5271. */
  5272. BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
  5273. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5274. },
  5275. CLASSIC | FLAG_NO_DATA,
  5276. {},
  5277. { {0x1, 0x42 } },
  5278. },
  5279. {
  5280. "SUB default X",
  5281. .u.insns = {
  5282. /*
  5283. * A = 0x66
  5284. * A = A - X
  5285. * ret A
  5286. */
  5287. BPF_STMT(BPF_LD | BPF_IMM, 0x66),
  5288. BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
  5289. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5290. },
  5291. CLASSIC | FLAG_NO_DATA,
  5292. {},
  5293. { {0x1, 0x66 } },
  5294. },
  5295. {
  5296. "SUB default A",
  5297. .u.insns = {
  5298. /*
  5299. * A = A - -0x66
  5300. * ret A
  5301. */
  5302. BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
  5303. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5304. },
  5305. CLASSIC | FLAG_NO_DATA,
  5306. {},
  5307. { {0x1, 0x66 } },
  5308. },
  5309. {
  5310. "MUL default X",
  5311. .u.insns = {
  5312. /*
  5313. * A = 0x42
  5314. * A = A * X
  5315. * ret A
  5316. */
  5317. BPF_STMT(BPF_LD | BPF_IMM, 0x42),
  5318. BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
  5319. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5320. },
  5321. CLASSIC | FLAG_NO_DATA,
  5322. {},
  5323. { {0x1, 0x0 } },
  5324. },
  5325. {
  5326. "MUL default A",
  5327. .u.insns = {
  5328. /*
  5329. * A = A * 0x66
  5330. * ret A
  5331. */
  5332. BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
  5333. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5334. },
  5335. CLASSIC | FLAG_NO_DATA,
  5336. {},
  5337. { {0x1, 0x0 } },
  5338. },
  5339. {
  5340. "DIV default X",
  5341. .u.insns = {
  5342. /*
  5343. * A = 0x42
  5344. * A = A / X ; this halt the filter execution if X is 0
  5345. * ret 0x42
  5346. */
  5347. BPF_STMT(BPF_LD | BPF_IMM, 0x42),
  5348. BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
  5349. BPF_STMT(BPF_RET | BPF_K, 0x42),
  5350. },
  5351. CLASSIC | FLAG_NO_DATA,
  5352. {},
  5353. { {0x1, 0x0 } },
  5354. },
  5355. {
  5356. "DIV default A",
  5357. .u.insns = {
  5358. /*
  5359. * A = A / 1
  5360. * ret A
  5361. */
  5362. BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
  5363. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5364. },
  5365. CLASSIC | FLAG_NO_DATA,
  5366. {},
  5367. { {0x1, 0x0 } },
  5368. },
  5369. {
  5370. "MOD default X",
  5371. .u.insns = {
  5372. /*
  5373. * A = 0x42
  5374. * A = A mod X ; this halt the filter execution if X is 0
  5375. * ret 0x42
  5376. */
  5377. BPF_STMT(BPF_LD | BPF_IMM, 0x42),
  5378. BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
  5379. BPF_STMT(BPF_RET | BPF_K, 0x42),
  5380. },
  5381. CLASSIC | FLAG_NO_DATA,
  5382. {},
  5383. { {0x1, 0x0 } },
  5384. },
  5385. {
  5386. "MOD default A",
  5387. .u.insns = {
  5388. /*
  5389. * A = A mod 1
  5390. * ret A
  5391. */
  5392. BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
  5393. BPF_STMT(BPF_RET | BPF_A, 0x0),
  5394. },
  5395. CLASSIC | FLAG_NO_DATA,
  5396. {},
  5397. { {0x1, 0x0 } },
  5398. },
  5399. {
  5400. "JMP EQ default A",
  5401. .u.insns = {
  5402. /*
  5403. * cmp A, 0x0, 0, 1
  5404. * ret 0x42
  5405. * ret 0x66
  5406. */
  5407. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
  5408. BPF_STMT(BPF_RET | BPF_K, 0x42),
  5409. BPF_STMT(BPF_RET | BPF_K, 0x66),
  5410. },
  5411. CLASSIC | FLAG_NO_DATA,
  5412. {},
  5413. { {0x1, 0x42 } },
  5414. },
  5415. {
  5416. "JMP EQ default X",
  5417. .u.insns = {
  5418. /*
  5419. * A = 0x0
  5420. * cmp A, X, 0, 1
  5421. * ret 0x42
  5422. * ret 0x66
  5423. */
  5424. BPF_STMT(BPF_LD | BPF_IMM, 0x0),
  5425. BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
  5426. BPF_STMT(BPF_RET | BPF_K, 0x42),
  5427. BPF_STMT(BPF_RET | BPF_K, 0x66),
  5428. },
  5429. CLASSIC | FLAG_NO_DATA,
  5430. {},
  5431. { {0x1, 0x42 } },
  5432. },
  5433. };
  5434. static struct net_device dev;
  5435. static struct sk_buff *populate_skb(char *buf, int size)
  5436. {
  5437. struct sk_buff *skb;
  5438. if (size >= MAX_DATA)
  5439. return NULL;
  5440. skb = alloc_skb(MAX_DATA, GFP_KERNEL);
  5441. if (!skb)
  5442. return NULL;
  5443. memcpy(__skb_put(skb, size), buf, size);
  5444. /* Initialize a fake skb with test pattern. */
  5445. skb_reset_mac_header(skb);
  5446. skb->protocol = htons(ETH_P_IP);
  5447. skb->pkt_type = SKB_TYPE;
  5448. skb->mark = SKB_MARK;
  5449. skb->hash = SKB_HASH;
  5450. skb->queue_mapping = SKB_QUEUE_MAP;
  5451. skb->vlan_tci = SKB_VLAN_TCI;
  5452. skb->vlan_proto = htons(ETH_P_IP);
  5453. skb->dev = &dev;
  5454. skb->dev->ifindex = SKB_DEV_IFINDEX;
  5455. skb->dev->type = SKB_DEV_TYPE;
  5456. skb_set_network_header(skb, min(size, ETH_HLEN));
  5457. return skb;
  5458. }
  5459. static void *generate_test_data(struct bpf_test *test, int sub)
  5460. {
  5461. struct sk_buff *skb;
  5462. struct page *page;
  5463. if (test->aux & FLAG_NO_DATA)
  5464. return NULL;
  5465. /* Test case expects an skb, so populate one. Various
  5466. * subtests generate skbs of different sizes based on
  5467. * the same data.
  5468. */
  5469. skb = populate_skb(test->data, test->test[sub].data_size);
  5470. if (!skb)
  5471. return NULL;
  5472. if (test->aux & FLAG_SKB_FRAG) {
  5473. /*
  5474. * when the test requires a fragmented skb, add a
  5475. * single fragment to the skb, filled with
  5476. * test->frag_data.
  5477. */
  5478. void *ptr;
  5479. page = alloc_page(GFP_KERNEL);
  5480. if (!page)
  5481. goto err_kfree_skb;
  5482. ptr = kmap(page);
  5483. if (!ptr)
  5484. goto err_free_page;
  5485. memcpy(ptr, test->frag_data, MAX_DATA);
  5486. kunmap(page);
  5487. skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
  5488. }
  5489. return skb;
  5490. err_free_page:
  5491. __free_page(page);
  5492. err_kfree_skb:
  5493. kfree_skb(skb);
  5494. return NULL;
  5495. }
  5496. static void release_test_data(const struct bpf_test *test, void *data)
  5497. {
  5498. if (test->aux & FLAG_NO_DATA)
  5499. return;
  5500. kfree_skb(data);
  5501. }
  5502. static int filter_length(int which)
  5503. {
  5504. struct sock_filter *fp;
  5505. int len;
  5506. if (tests[which].fill_helper)
  5507. return tests[which].u.ptr.len;
  5508. fp = tests[which].u.insns;
  5509. for (len = MAX_INSNS - 1; len > 0; --len)
  5510. if (fp[len].code != 0 || fp[len].k != 0)
  5511. break;
  5512. return len + 1;
  5513. }
  5514. static void *filter_pointer(int which)
  5515. {
  5516. if (tests[which].fill_helper)
  5517. return tests[which].u.ptr.insns;
  5518. else
  5519. return tests[which].u.insns;
  5520. }
  5521. static struct bpf_prog *generate_filter(int which, int *err)
  5522. {
  5523. __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
  5524. unsigned int flen = filter_length(which);
  5525. void *fptr = filter_pointer(which);
  5526. struct sock_fprog_kern fprog;
  5527. struct bpf_prog *fp;
  5528. switch (test_type) {
  5529. case CLASSIC:
  5530. fprog.filter = fptr;
  5531. fprog.len = flen;
  5532. *err = bpf_prog_create(&fp, &fprog);
  5533. if (tests[which].aux & FLAG_EXPECTED_FAIL) {
  5534. if (*err == tests[which].expected_errcode) {
  5535. pr_cont("PASS\n");
  5536. /* Verifier rejected filter as expected. */
  5537. *err = 0;
  5538. return NULL;
  5539. } else {
  5540. pr_cont("UNEXPECTED_PASS\n");
  5541. /* Verifier didn't reject the test that's
  5542. * bad enough, just return!
  5543. */
  5544. *err = -EINVAL;
  5545. return NULL;
  5546. }
  5547. }
  5548. if (*err) {
  5549. pr_cont("FAIL to prog_create err=%d len=%d\n",
  5550. *err, fprog.len);
  5551. return NULL;
  5552. }
  5553. break;
  5554. case INTERNAL:
  5555. fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
  5556. if (fp == NULL) {
  5557. pr_cont("UNEXPECTED_FAIL no memory left\n");
  5558. *err = -ENOMEM;
  5559. return NULL;
  5560. }
  5561. fp->len = flen;
  5562. /* Type doesn't really matter here as long as it's not unspec. */
  5563. fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
  5564. memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
  5565. /* We cannot error here as we don't need type compatibility
  5566. * checks.
  5567. */
  5568. fp = bpf_prog_select_runtime(fp, err);
  5569. if (*err) {
  5570. pr_cont("FAIL to select_runtime err=%d\n", *err);
  5571. return NULL;
  5572. }
  5573. break;
  5574. }
  5575. *err = 0;
  5576. return fp;
  5577. }
  5578. static void release_filter(struct bpf_prog *fp, int which)
  5579. {
  5580. __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
  5581. switch (test_type) {
  5582. case CLASSIC:
  5583. bpf_prog_destroy(fp);
  5584. break;
  5585. case INTERNAL:
  5586. bpf_prog_free(fp);
  5587. break;
  5588. }
  5589. }
  5590. static int __run_one(const struct bpf_prog *fp, const void *data,
  5591. int runs, u64 *duration)
  5592. {
  5593. u64 start, finish;
  5594. int ret = 0, i;
  5595. start = ktime_get_ns();
  5596. for (i = 0; i < runs; i++)
  5597. ret = BPF_PROG_RUN(fp, data);
  5598. finish = ktime_get_ns();
  5599. *duration = finish - start;
  5600. do_div(*duration, runs);
  5601. return ret;
  5602. }
  5603. static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
  5604. {
  5605. int err_cnt = 0, i, runs = MAX_TESTRUNS;
  5606. for (i = 0; i < MAX_SUBTESTS; i++) {
  5607. void *data;
  5608. u64 duration;
  5609. u32 ret;
  5610. if (test->test[i].data_size == 0 &&
  5611. test->test[i].result == 0)
  5612. break;
  5613. data = generate_test_data(test, i);
  5614. if (!data && !(test->aux & FLAG_NO_DATA)) {
  5615. pr_cont("data generation failed ");
  5616. err_cnt++;
  5617. break;
  5618. }
  5619. ret = __run_one(fp, data, runs, &duration);
  5620. release_test_data(test, data);
  5621. if (ret == test->test[i].result) {
  5622. pr_cont("%lld ", duration);
  5623. } else {
  5624. pr_cont("ret %d != %d ", ret,
  5625. test->test[i].result);
  5626. err_cnt++;
  5627. }
  5628. }
  5629. return err_cnt;
  5630. }
  5631. static char test_name[64];
  5632. module_param_string(test_name, test_name, sizeof(test_name), 0);
  5633. static int test_id = -1;
  5634. module_param(test_id, int, 0);
  5635. static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
  5636. module_param_array(test_range, int, NULL, 0);
  5637. static __init int find_test_index(const char *test_name)
  5638. {
  5639. int i;
  5640. for (i = 0; i < ARRAY_SIZE(tests); i++) {
  5641. if (!strcmp(tests[i].descr, test_name))
  5642. return i;
  5643. }
  5644. return -1;
  5645. }
  5646. static __init int prepare_bpf_tests(void)
  5647. {
  5648. int i;
  5649. if (test_id >= 0) {
  5650. /*
  5651. * if a test_id was specified, use test_range to
  5652. * cover only that test.
  5653. */
  5654. if (test_id >= ARRAY_SIZE(tests)) {
  5655. pr_err("test_bpf: invalid test_id specified.\n");
  5656. return -EINVAL;
  5657. }
  5658. test_range[0] = test_id;
  5659. test_range[1] = test_id;
  5660. } else if (*test_name) {
  5661. /*
  5662. * if a test_name was specified, find it and setup
  5663. * test_range to cover only that test.
  5664. */
  5665. int idx = find_test_index(test_name);
  5666. if (idx < 0) {
  5667. pr_err("test_bpf: no test named '%s' found.\n",
  5668. test_name);
  5669. return -EINVAL;
  5670. }
  5671. test_range[0] = idx;
  5672. test_range[1] = idx;
  5673. } else {
  5674. /*
  5675. * check that the supplied test_range is valid.
  5676. */
  5677. if (test_range[0] >= ARRAY_SIZE(tests) ||
  5678. test_range[1] >= ARRAY_SIZE(tests) ||
  5679. test_range[0] < 0 || test_range[1] < 0) {
  5680. pr_err("test_bpf: test_range is out of bound.\n");
  5681. return -EINVAL;
  5682. }
  5683. if (test_range[1] < test_range[0]) {
  5684. pr_err("test_bpf: test_range is ending before it starts.\n");
  5685. return -EINVAL;
  5686. }
  5687. }
  5688. for (i = 0; i < ARRAY_SIZE(tests); i++) {
  5689. if (tests[i].fill_helper &&
  5690. tests[i].fill_helper(&tests[i]) < 0)
  5691. return -ENOMEM;
  5692. }
  5693. return 0;
  5694. }
  5695. static __init void destroy_bpf_tests(void)
  5696. {
  5697. int i;
  5698. for (i = 0; i < ARRAY_SIZE(tests); i++) {
  5699. if (tests[i].fill_helper)
  5700. kfree(tests[i].u.ptr.insns);
  5701. }
  5702. }
  5703. static bool exclude_test(int test_id)
  5704. {
  5705. return test_id < test_range[0] || test_id > test_range[1];
  5706. }
  5707. static __init int test_bpf(void)
  5708. {
  5709. int i, err_cnt = 0, pass_cnt = 0;
  5710. int jit_cnt = 0, run_cnt = 0;
  5711. for (i = 0; i < ARRAY_SIZE(tests); i++) {
  5712. struct bpf_prog *fp;
  5713. int err;
  5714. if (exclude_test(i))
  5715. continue;
  5716. pr_info("#%d %s ", i, tests[i].descr);
  5717. fp = generate_filter(i, &err);
  5718. if (fp == NULL) {
  5719. if (err == 0) {
  5720. pass_cnt++;
  5721. continue;
  5722. }
  5723. err_cnt++;
  5724. continue;
  5725. }
  5726. pr_cont("jited:%u ", fp->jited);
  5727. run_cnt++;
  5728. if (fp->jited)
  5729. jit_cnt++;
  5730. err = run_one(fp, &tests[i]);
  5731. release_filter(fp, i);
  5732. if (err) {
  5733. pr_cont("FAIL (%d times)\n", err);
  5734. err_cnt++;
  5735. } else {
  5736. pr_cont("PASS\n");
  5737. pass_cnt++;
  5738. }
  5739. }
  5740. pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
  5741. pass_cnt, err_cnt, jit_cnt, run_cnt);
  5742. return err_cnt ? -EINVAL : 0;
  5743. }
  5744. static int __init test_bpf_init(void)
  5745. {
  5746. int ret;
  5747. ret = prepare_bpf_tests();
  5748. if (ret < 0)
  5749. return ret;
  5750. ret = test_bpf();
  5751. destroy_bpf_tests();
  5752. return ret;
  5753. }
  5754. static void __exit test_bpf_exit(void)
  5755. {
  5756. }
  5757. module_init(test_bpf_init);
  5758. module_exit(test_bpf_exit);
  5759. MODULE_LICENSE("GPL");