test_bpf.c 159 KB

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